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
- How to get the function name inside a function in PHP ?
- D3.js | d3.hcl() Function
- D3.js | d3.lab() Function
- PHP | Ds\Set contains() Function
- PHP | exp() Function
- D3.js | d3.hsl() Function
- p5.js | int() function
- p5.js | hue() function
- PHP Ds\Set sum() Function
- PHP | Ds\Map first() Function
- p5.js | nfs() Function
- p5.js | nfp() Function
- PHP Ds\Map sum() 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.