PHP randomly generates a unique HASH value UDF, which is a phphphash UDF. PHP randomly generates a unique HASH value user-defined function. the phphphash user-defined function has many ways to obtain random and unique HASH values on the Internet, but the difference is similar: 1. first obtain the random and unique string. PHP randomly generates the unique HASH value Udfs. phphash UDFs
There are many ways to obtain random and unique HASH values on the Internet, but they are similar:
1. obtain random and unique strings first
2. calculate the HASH value using MD5 or sha1.
When a project uses the hash value, it finds it online, but finds that a function in PHP can directly generate a unique string-uniqid (). by using this function, in addition, the random number generated by the user (to prevent cracking) is more unique and difficult to guess. The main considerations are as follows:
1. Random efficiency and randomness: the choice of the rand and mt_rand functions is the first choice. mt_rand features high efficiency and good randomness;
2. random number of times: Select 5 times. Originally, the unniqid is unique. In addition, the random number can only enhance security, and the number of times is sufficient.
3. md5 or sha1: can generate a unique hash value. sha1 may occupy a high resource, but it is very small. if you consider the lower case of database storage, 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 ();?>
There are many ways to obtain random and unique HASH values on the consumer network, but they are similar: 1. obtain random and unique strings first...