Get the App
SLTechnology News&Howtos  ›  Development  › 

How to randomly generate a unique hash value custom function by PHP

Shulou Source: shulou.com Published: 2022-06-03 19:44:26 11月12日 Update

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!

Tags: Function generation content character string efficiency article randomness selection not easy security more or less the same negligible value interest just uniqueness security guys buddies Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia Redmi Linux macOS MySQL