How to randomly generate a unique hash value custom function by PHP
This article mainly introduces how PHP randomly generates a unique hash value custom function, which is very detailed and has a certain reference value. Interested friends must read it!
There are many ways to get random and unique hash values on the Internet, but they are more or less the same:
1. Get the random unique string first
2. Calculate the hash value by MD5 or sha1
A project to use hash value, look for it on the Internet, but found that PHP has a function that can directly generate a unique string-uniqid (), by using this function, plus their own generated random numbers (to prevent cracking), more unique and not easy to guess. The main considerations are as follows:
1. Random efficiency and randomness: the choice of rand and mt_rand functions, the first choice is mt_rand, with high efficiency and good randomness.
2. Random times: select 5 times, unniqid is unique, plus random times can only enhance security, 5 times is enough
3. Md5 or sha1: both can generate a unique hash value. The resource consumption of sha1 may be high, but it is very small. If you consider the lowercase of database storage, you can use md5 (32-bit length).
The above is all the contents of the article "how to randomly generate a unique hash value custom function by PHP". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!