UUID (Universally unique Identifier), the GUID is expected to generate a unique identifier within the entire space-time range, which is necessary in a distributed computing environment. However, if you simply want to generate a "local unique identifier" in a limited local environment, using the UUID is overkill, the "local unique identifier", which I call LUID (the locals unique Identifier)
For example, when I use PHP to develop a Web site program, in order to avoid users at the same time open the same Web page to cause the session name conflict problem, the hope is to save the session is not $_session[' param '], but $_session[$luid [' param '], The $luid value is passed in other ways to ensure that the ' param ' parameter is not overwritten. Looking for someone else's solution, is to generate a UUID, and the algorithm to generate a UUID hundreds of lines. I consider that because it is in the session space, is a limited environment, the uniqueness of the strength does not have to be too high, as long as the same session of the lifetime of the only can, so there is the following code:
Copy Code code as follows:
/**
* Returns a unique string that is unique in the local system.
* Returns a 32 character string, in the form of ' 7dac352074f221f3edc74d265c65a636 ', or ' D198D8FC56FFED627F3F8313D6F06ACF '
*/
function Luid () {
Return MD5 (Microtime ());
}
Actually on one line. Return MD5 (Microtime ());
The string returned by reason Microtime () is already unique, I measured, even if the continuous execution of microtime (), the return value has a difference of more than 100US, and the user clicks, and on the network transfer again by the server processing interval far more than dozens of Ms. Plus MD5 just makes the results messy.