How to Generate a Unique ID in PHP
A unique user ID which will be created at PHP using uniqid () function. Function is said to have two parameters you can now set.
The first is siad to be the prefix, which is what to be appended to the beginning of each ID. The second is more_entropy. If it is false or not specified which will return 13 characters; if it’s true, 23 characters is said to be returned.
EXAMPLES FOR CREATING A UNIQUE ID
Below are some examples of creating up unique user ID but each area has various different. First create a normal unique ID as the second is said to show how to make a longer ID. Third examples creates an ID with random number as prefix while last line to encrypt username before storing it.
//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 – more secure than a static prefix $c = uniqid (rand (),true); echo $c; echo “<br>”;
//this md5 encrypts the username from above, so its ready to be stored in your database $md5c = md5($c); echo $md5c; ?>