PHP uniqid() Function

❮ PHP Misc Reference

Example

Generate a unique ID:

<?php
echo uniqid();
?>
Try it Yourself »

Definition and Usage

The uniqid() function generates a unique ID based on the microtime (the current time in microseconds).


Syntax

uniqid(prefix,more_entropy)

Parameter Values

Parameter Description
prefix Optional. Specifies a prefix to the unique ID (useful if two scripts generate ids at exactly the same microsecond)
more_entropy Optional. Specifies more entropy at the end of the return value. This will make the result more unique. When set to TRUE, the return string will be 23 characters. Default is FALSE, and the return string will be 13 characters long

Technical Details

Return Value: Returns the unique identifier, as a string
PHP Version: 4+
Changelog: The prefix parameter became optional in PHP 5.0.
The limit of 114 characters long for prefix was raised in PHP 4.3.1.

❮ PHP Misc Reference
Copyright 1999-2023 by Refsnes Data. All Rights Reserved.