PHP randomly generates a unique hash value custom function, Phphash custom function
There are many ways to get random, unique hash values on the Web, but they are similar:
1. Get a random, unique string first
2, MD5 or SHA1 to calculate the hash value
A project to use the hash value, went to search the Internet, but found that PHP has a function can directly generate a unique string--uniqid (), by using this function, coupled with their own generated random number (to prevent being cracked), more unique and difficult to guess. The main issues to consider are as follows:
1. Stochastic efficiency and randomness: Rand and Mt_rand function selection, preferred mt_rand, high efficiency, good randomness;
2, Random times: Choose 5 times, originally Unniqid is the only, plus random can just enhance security, 5 times is sufficient
3, MD5 or SHA1: can generate a unique hash value, SHA1 occupy resources may be high, but very little, if you consider the database storage of lowercase, you can use MD5 (32-bit length)
<?phpfunction Get_hash () { $chars = ' abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz0123456789!@#$%^ &* () +-'; $random = $chars [Mt_rand (0,73)]. $chars [Mt_rand (0,73)]. $chars [Mt_rand (0,73)]. $chars [Mt_rand (0,73)]. $chars [Mt_rand (0,73)];/ /random 5 times $content = Uniqid (). $random; Similar to 5443e09c27bf4ab4ut return SHA1 ($content);} Echo Get_hash ();? >
http://www.bkjia.com/PHPjc/987256.html www.bkjia.com true http://www.bkjia.com/PHPjc/987256.html techarticle PHP randomly generates a unique hash value custom function, Phphash custom function Online There are many ways to get random unique hash value, but the same thing: 1, first get the random unique string ...