The uniqid() function in PHP is an inbuilt function which is used to generate a unique ID based on the current time in microseconds (micro time).
The ID generated from the uniqid() function is not optimal since it is based on the system time and is not cryptographically secured. Thus it should not be for cryptographical purposes.
The uniqid( ) function accepts prefix and more_entropy as parameters and returns timestamp based unique identifier as a string.
Parameters Used: The uiqid() function in PHP accepts two parameters.
- $prefix : It is an optional parameter which specifies a prefix to the unique id.
- $more_entropy : It is an optional parameter which specifies more entropy at the end of the return value which makes the id more unique.The default value is FALSE, which returns 13 characters long string whereas when it is set to TRUE, the return string is 23 characters long.
Return Value: It returns timestamp based unique identifier as a string.
Errors And Exceptions
- The uniqid() function tries to create unique identifier, but it does not guarantee 100% uniqueness of return value.
- Since most systems adjust system clock by NTP or like, system time is changed constantly. Therefore, it is possible that this function does not return unique ID for the process/thread.
Below programs illustrate the uniqid() function:
Reference : http://php.net/manual/en/function.uniqid.php
- D3.js | d3.rgb() Function
- D3.js | d3.map.set() Function
- PHP | Ds\Set contains() Function
- PHP | min( ) Function
- PHP | max( ) Function
- PHP | key() Function
- PHP | Ds\Set add() Function
- p5.js | cos() function
- CSS | rgb() Function
- PHP | pos() Function
- p5.js | log() function
- PHP | Ds\Set first() Function
- D3.js | d3.hcl() Function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.