The example in this article describes the usage of uniqid() function in PHP. Share it with everyone for your reference. The specific method analysis is as follows:
The uniqid() function generates a unique ID based on the current time in microseconds.
Note: The ID generated by this function is suboptimal because it is based on system time. To generate an absolutely unique ID, use the md5() function (find it in the String Functions Reference).
Let’s take a look at the following code:
It can be concluded that uniqid is the current time accurate to microseconds, multiplied by 1048576 (2 to the 20th power) and finally converted to hexadecimal.
After knowing the relationship between uniqid and time, uniqid can have a wider range of uses. For example, uniqid can be used as the file name of a post in a forum.
In the post index, you can easily search for posts by time.
Looking at the above and below codes, I think its function is to generate a non-repeating 32-bit character
The uniqid() function itself is based on the current time in microseconds, so duplication will definitely occur in high concurrency situations. The solution is that you can generate a random number under this premise, and then The combination of the two produces a new number, which will reduce the probability of repetition. If you still want to be more precise, you can also add the MD5 code of the client's IP to generate it together. In this way, the probability of duplication is extremely low, and it can be said that there will be almost no duplication.
I hope this article will be helpful to everyone’s PHP programming design.
uniqid
produces a value of only one.
Syntax: string uniqid(string prefix);
Return value: String
Function type: Encoding processing
Content description
This function will be based on the current millisecond and the specified prefix string Produces a unique string. The parameter prefix is the preceding string, which can be up to 114 characters.
echo uniqid(); You can see that uniqid is always a changing hexadecimal number with a length of 13.
echo hexdec(uniqid())/(time()+microtime());
?>
The output is basically around 1048576.
It can be concluded that uniqid is the current time accurate to microseconds, multiplied by 1048576 (2 to the 20th power) and finally converted to hexadecimal.
After knowing the relationship between uniqid and time, uniqid can be used for a wider range of purposes. For example, in a text forum, uniqid can be used as the file name of a post.
In the post index, you can easily search for posts by time.
Reference: hi.baidu.com/...7.html
846189340160532f6c51bf26ab596f55
It will be used when detecting security horses
?>
It is also used when making random numbers