Home >Backend Development >PHP Tutorial >PHP code to generate local unique identification code LUID_PHP tutorial
UUID (Universally Unique Identifier) and GUID hope to generate unique identification codes throughout the entire space and time range, which is necessary in a distributed computing environment. However, if you only want to generate a unique identification code in a restricted local environment, A "local unique identifier", using UUID is just overkill. This "local unique identifier", I call it LUID (Local Unique Identifier)
For example, when I use PHP to develop website programs, In order to avoid session name conflicts caused by users opening the same web page multiple times at the same time, we hope that the saved session is not $_SESSION['param'], but $_SESSION[$luid]['param'], and then pass $ through other methods. luid value to ensure that the 'param' parameter is not overwritten. After searching for other people's solutions, they all generate UUID, and the algorithm for generating UUID is filled with hundreds of lines. I considered that because it is in the SESSION space, it is a restricted The uniqueness of the environment does not need to be too high, as long as it is unique within the lifetime of the same SESSION, so the following code is available: