Possible Duplicate:
PHP: How to generate a random, unique, alphanumeric string?
I’m trying to generate unique id (alpha-numeric string). I’m using curent timestamp for that. I have two questions:
- Will
md5(stamp1)be different frommd5(stamp2)ifstamp1 != stamp2. - Is there a common way to generate unique string?
PS: the easiest way of cause is to take stamp as id. Still I dont want that it was easy to find out how id is generated
Yes, in most cases, they will be different. Chances of hash collisions are very, very low (think one in billions).
The built in function
uniqid()is great for this. You could even domd5(uniqid()), but be aware, this won’t increase the entropy of the GUID. For increased entropy, you can call the function like this:uniqid('',TRUE);