Forum Moderators: coopster
Hi:
a built function uniqid() says it can genrate a unique id.
for example, using the following code:
<?php
$user_id = md5(uniqid(rand(), true));
?>
but my question is that the ids generated from the above code and from different date are 100% different each other.
for example:
21/01/08, id=iuuj1ll;
22/01/08, id=ppokjjk;
7/09/08, id=klkkk1;
and so.
If you want completly random id's then you will need to make your own function, as an md5 or sha1 will not help. As these will provide you with a fixed length string. You could chop an md5 string at a random position, but then you would need to check that this string is unique and not just random.
So are you after unique or random or both?
<edit>
You may also want to look at the user comment as there is
<?php
$better_token = uniqid(md5(rand()), true);
?>
[edited by: PHP_Chimp at 11:41 am (utc) on Mar. 29, 2008]