Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 381
  • Last Modified:

PHP and creating unique user id's

I am creating a web site using the PHP scripting language. Users are going to set up their own account when they register. I want each user to have a unique ID. I of course will then use that id to track their visit around the site so when they do something that uses a database, it will use that unique identifier to associate given records with that user. Should I use the unique id from a database when they register or is there a better way to do it. Any thoughts or ideas would be appreciated.
  • 2
1 Solution
What is usually being done is that in an table with users,there is autoincrement id field that increments automatically on every user insert. That is sufficient for a unique ID.

Now if you really want to be unique, that is if your server handles so much data that there is a chance for 2 request to happen at the same millisecond (which is rare, unless you are running something gigantic) you can use php own UUID (universal unique identifier) function uniqid() http://bs.php.net/uniqid
Cant get more unique than this :S (look at example output)

But id say database autoincrement is sufficient.

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now