Reputation: 410
Usually, when I'm developing websites which interact with clients, I used to use their usernames or user IDs to save their configs and so on. But now I'm developing a website with no login system and I need to save some things, like "likes", "Accessed pages" and more.
I've tried Internet Protocol (IP) but it won't work when the visitors are under NAT or Proxy.
How can I create an unique ID for every single user and them save it in my database?
By the way I'm using PHP.
Upvotes: 2
Views: 4697
Reputation: 3172
This sounds like a recipe for disaster if you are trying to save user data long term.
I would recommend:
The problem arises when the user clears their browsing history/cookies and now there is no way to retrieve that user's activity because it's all based on that hash.
I guess one work-around would be to send an email to the user with their hash and instruct them on how to reinitialize their activity history.
You would have to create a special page where they could enter their hash and your system would reset the cookies on their system.
Upvotes: 3
Reputation: 373
do {
$uniqueID = uniqid();
$exists = mysql_num_rows('SELECT * FROM table WHERE id = $uniqueID');
} while ($exists == 1)
I'm using a similar code to generate unique IDs, and it works fine for me. Or, to make it even simpler, you could just use the uniqid()
function, which shouldn't ever really generate two of the same results.
Upvotes: 2