The uniqid in PHP is a duplicate problem in high concurrency, phpuniqid
The token verification has been generated in recent projects. First, use the uniqid () function in php to generate random strings. However, this function is based on microsecond time. In the case of high concurrency, the same value may be generated.
Solution 1: uniqid (rand (). The first parameter of this function can be used as the prefix of the number of generations, which greatly reduces the repetition rate of the number of generators. But the possibility of repetition still exists.
Solution 2: md5 (uniqid (). Use the md5 () function to generate an absolutely unique value.
In php, help me explain the uniqid () function. I found it in English in the php manual.
Uniqid
Generate only one value.
Syntax: string uniqid (string prefix );
Return Value: String
Function Type: Encoding
Description
This function generates a unique string based on the current millisecond and specified prefix string. The prefix parameter is a prefix string that can contain up to 114 characters.
Echo uniqid (); we can see that uniqid is always a hexadecimal number with a continuously changing length of 13.
<? Php
Echo hexdec (uniqid ()/(time () + microtime ());
?>
The output is about 1048576.
It can be concluded that uniqid is obtained after the current time is accurate to microsecond and then multiplied by 1048576 (20 power of 2) and finally converted to hexadecimal.
Uniqid can be used more widely after you know the relationship between uniqid and time. For example, uniqid can be used as the file name of a post in a text forum.
In the post index, you can easily search for a post by time.
Reference: hi.baidu.com/...7.html
When learning PHP, how can I use uniqid ()?
846189340160532f6c51bf26ab596f55
Used for Security Testing
<? Phpechomd5 (uniqid (rand (), 1 ));
?>
It will also be used when there is a random number.