Description: The method used to generate the random string has Mt_rand ()
The method used to generate the unique string has MD5 (), uniqid (), Microtime ()
Code:
1<?PHP2 /*3 * Generate random string4 * @param int $length to generate the length of a random string5 * @param string $char strings that make up a random string6 * A random string generated @return string $string7 */8 functionStr_rand ($length= 32,$char= ' 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ') {9 if(!Is_int($length) ||$length< 0) {Ten return false; One } A - $string= ' '; - for($i=$length;$i> 0;$i--) { the $string.=$char[Mt_rand(0,strlen($char)-1)]; - } - - return $string; + } - + EchoStr_rand (), "<br/>"; A at /* - * Generate 32-bit unique strings - */ - $uniqid=MD5(uniqid(Microtime(true),true)); - Echo $uniqid;
PHP generates random strings and unique strings