8

How to create a unique identifier for users without a user name - PHP

 2 years ago
source link: https://www.codesd.com/item/how-to-create-a-unique-identifier-for-users-without-a-user-name-php.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

How to create a unique identifier for users without a user name - PHP

advertisements

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.


This sounds like a recipe for disaster if you are trying to save user data long term.

I would recommend:

  1. Create a random but unique hash and save that to a database.
  2. Set the hash as a cookie on the user's computer.
  3. Save all 'likes', 'accessed pages', et al. to the database keyed on the hash.

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.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK