By default, the generated unique ID returns a string of 13 characters. If the prefix of the unique ID is not defined, a maximum of 23 strings can be returned. If you combine the md5 () function, the generated unique ID is more reliable. This generated ID has the biggest advantage of sorting than the random ID, especially in databases. I. function prototype str
By default, the generated unique ID returns a string of 13 characters. If the prefix of the unique ID is not defined, a maximum of 23 strings can be returned. If you combine the md5 () function, the generated unique ID is more reliable. This generated ID has the biggest advantage of sorting than the random ID, especially in databases. I. function prototype str
By default, the generated unique ID returns a string of 13 characters. If the prefix of the unique ID is not defined, a maximum of 23 strings can be returned. If you combine the md5 () function, the generated unique ID has a higher reliability. This generated ID has the biggest advantage of sorting than the random ID, especially the values that need to be stored in the database.
I. function prototype
String uniqid ([string prefix [, bool more_entropy])
You can define the prefix and length of a unique ID.
2. Version compatibility
PHP 3, PHP 4, PHP 5
III. Basic Function usage and Examples
1. Generate a unique ID
echo uniqid();
?>
2. Use the md5 () function to generate a unique ID.
echo md5(uniqid());
?>
Output: dfbc5c8c6438de075da28b3c8a413fd0
3. Multiple unique IDs are generated, because they are measured in microseconds.
echo uniqid();
echo uniqid();
echo uniqid();
?>
Output:
4bfd0e375108b
4bfd0e3753981
4bfd0e3753983
According to the generated results, unique IDs are sorted.
Use the uniqid () function to generate a unique ID. This function can be used to generate both temporary IDs and permanent unique IDs (stored in the database). For more information, see the PHP manual.