CancelImage Upload

Producing a random and unique ID code for your users in PHP

If you want to give your users a specific code you will need to make sure that it really is random and unique. To accomplish this task PHP has a suitable function to offer, as it usually does:

<?php

$unique_id = uniqid("userid_");

echo $unique_id;

?>

The key here of course is the function uniqid(). The value defined within it's brackets is a prefix, and can be either left empty or be changed to something more suitable. The result of the above code will be something along these lines:

userid_4aa2cbece74cb

And of course to take things one step further we can always call on the PHP function md5() to generate a completely random piece of code:

<?php

$unique_id = uniqid();

$unique_code = md5($unique_id);

echo $unique_code;

?>


Login
Want to leave a comment?

No problem. Just enter your email and password below.


register | home | reminder

myDesignTool Networking • www.mydesigntool.cominfo@mydesigntool.com