X
HOME HTML5 CSS3 JAVASCRIPT SQL PHP5 JQUERY ANGULAR BOOTSTRAP3 XML MORE...
REFERENCES | EXAMPLES | FORUM | ABOUT

PHP uniqid() Function

PHP Misc Reference PHP Misc Reference

Example

Generate a unique ID:

<?php
echo uniqid();
?>

Run example »

Definition and Usage

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

Note: The generated ID from this function is not optimal, because it is based on the system time. To generate an extremely difficult to predict ID, use the md5() function.


Syntax

uniqid(prefix,more_entropy)

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 PHP Misc Reference

Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]
Search w3schools.com:

WEB HOSTING

UK Reseller Hosting

WEB BUILDING

Download XML Editor FREE Website BUILDER Free HTML5 Templates

SHARE THIS PAGE

facebook