Buy Cheap Software - Discount Software Generate unique user ID using uniqid () - Le Minh Duc
Generate unique user ID using uniqid ()
Friday, 26 May 2006

You sign up for a site and they generate you a unique user ID to use. One way to do this in PHP is to use the uniqid () function. This with generate a 13 or 23 character unique ID, which you can then add a prefix to if you desire. Once you send this to the user, you can then encrypt and store it in the database.

Generating a unique ID for members of your site: Uniqid (prefix, more_entropy)

A unique site ID can be created in PHP using the uniqid () function. This function has two parameters we can set. The first is the prefix. This is what will be appended to the beginning of each ID. The second is more_entropy. If this is false or not specified it will return 13 characters, if it is true then 23 characters will be returned.

 <?php     

//creates a unique id with the 'about' prefix
$a = uniqid(about);
echo $a;
echo "<br>";

//creates a longer unique id with the 'about' prefix$b = uniqid (about, true);
Echo $b;
echo "<br>";

//creates a unique ID with a random number as a prefix
$c = uniqid (rand (),true);
echo $c;
echo "<br>";

//this md5 encrypts the username from above to be stored in your database

$md5c = md5($c);
echo $md5c;
?>



Be first to comment this article

Only registered users can write comments.
Please login or register.

Powered by AkoComment Tweaked Special Edition v.1.4.6
AkoComment © Copyright 2004 by Arthur Konze - www.mamboportal.com
All right reserved

 
Next >
Beautiful Scenery