Use the uniqid () function in php to generate a unique id.
Function createId ($ prefix = "") {$ str = md5 (uniqid (mt_rand (), true); return $ prefix. $ str;} // uniqid (prefix, more_entropy)
The uniqid () function generates a unique ID based on the current time in microseconds. Prefix is optional. It is the prefix specified by ID. This parameter is useful if two scripts generate IDS exactly in the same microsecond. More_entropy is optional. Specify more entropy at the end of the returned value. If the prefix parameter is null, the returned string contains 13 characters in length. If the more_entropy parameter is set to true, it is a string of 23 characters. If the more_entropy parameter is set to true, an extra entropy is added at the end of the returned value (the program is generated using the combination of linear and remainder values), which improves the uniqueness of the result. The Return Value Returns a unique identifier in the form of a string. Tip and comment: because the system time is used, the ID generated by this function is not optimal. To generate an absolutely unique ID, use the md5 () function (find it in the string function reference) // mt_rand () to return a random integer using the Mersenne Twister algorithm. Mt_rand (min, max) indicates that if the optional parameters min and max are not provided, mt_rand () returns a pseudo-random number between 0 and RAND_MAX. For example, if you want a random number between 5 and 15 (including 5 and 15), use mt_rand (5, 15 ). Many old libc random number generators have some uncertain and unknown features and are very slow. The rand () function of PHP uses the libc random number generator by default. The mt_rand () function is informal to replace it. This function uses known features in Mersenne Twister as a random number generator, which can generate random values at an average speed four times faster than the rand () provided by libc.