Use the uniqid function of PHP to generate a unique ID.

Source: Internet
Author: User
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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.