Php returns a Unique string that is Unique in the local system. For more information, see UUID (Universally Unique Identifier, 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:
The 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.