PHP unique id

09.Jul.2010

To generate PHP unique id, you can use PHP function uniqid(). This PHP function generates a prefixed unique identifier based on the current time in microseconds.

1
2
//returns 13 character long unique id
echo uniqid();

If you want to generate identifiers simultaneously on different servers, they might try to generate identifier at the same microsecond, therefore it can be useful to add prefix, or more_entropy param in order to get “more unique” id.

PHP unique id without prefix:

1
2
//returns 23 character long unique id
echo uniqid('', true);

PHP unique id with prefix “unique_”:

1
2
//returns 23 character long unique id
echo uniqid('unique_', true);