Php code for generating a local Unique Identification Code LUID

Source: Internet
Author: User

UUID (Universally Unique Identifier) and GUID are all Unique identifiers in the whole time and space range. This is necessary in a distributed computing environment. however, if you only want to generate a "local unique identifier" in a limited local environment, using UUID is the "local unique identifier ", I call it LUID (Local Unique Identifier)

For example, when I develop a website program using php, to avoid session name conflicts caused by multiple times of opening the same webpage, the session you want to save is not $ _ SESSION ['param'], but $ _ SESSION [$ luid] ['param']. Then, you can pass the $ luid value in other ways, ensure that the 'param' parameter is not overwritten. after finding out the solutions of others, they all generate UUID, And the UUID generation algorithm has hundreds of lines. I have considered that it is a limited environment in the SESSION space, and its uniqueness strength does not have to be too high. It is only required to be unique within the life cycle of the same SESSION, the following code is available:

Copy codeThe Code is as follows :/**
* Returns a unique string that is unique in the local system,
* The return value is a 32-character string in the format of '7dac352074f221f3edc74d265c65a636 'or 'd198d8fc56ffed627f3f8313d6f06acf'
*/
Function LUID (){
Return MD5 (microtime ());
}

In fact, there is only one line. return MD5 (microtime ());

The strings returned by microtime () are already unique. I tested that even if we execute microtime () continuously, the returned values are more than us, the interval between transmitting data over the network and processing data by the server is much more than dozens of ms. adding md5 only makes the results messy.

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.