PHP and creating unique user id's

Posted on 2007-08-08
Last Modified: 2013-12-12
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.
Question by:tarrigo
    LVL 11

    Expert Comment

    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()
    LVL 11

    Accepted Solution

    Cant get more unique than this :S (look at example output)

    But id say database autoincrement is sufficient.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
    Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
    The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
    The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now