uniqid

Generate a unique ID

Syntax

uniqid(string $prefix = "", bool $more_entropy = false): string

Parameters

prefix

Can be useful, for instance, if you generate identifiers simultaneously on several hosts that might happen to generate the identifier at the same microsecond.

With an empty prefix, the returned string will be 13 characters long. If more_entropy is TRUE, it will be 23 characters.

more_entropy

If set to TRUE, uniqid() will add additional entropy (using the combined linear congruential generator) at the end of the return value, which increases the likelihood that the result will be unique.

Return

Returns timestamp based unique identifier as a string.

Warning: This function tries to create a unique identifier, but it does not guarantee a 100% uniqueness of return value.

Examples

1 · void

<?

$return = uniqid();

echo $return;

?>
63df22949659d

2 · prefix

<?

$prefix = 'prefix';

$return = uniqid($prefix);

echo $return;

?>
prefix63df2294a4880

3 · more_entropy

<?

$prefix = 'prefix';
$more_entropy = true;

$return = uniqid($prefix, $more_entropy);

echo $return;

?>
prefix63df2294b1cde9.79804273

__halt_compiler

connection_aborted

connection_status

constant

define

defined

die

eval

exit

highlight_file

highlight_string

hrtime

ignore_user_abort

pack

php_strip_whitespace

show_source

sleep

sys_getloadavg

time_nanosleep

time_sleep_until

unpack

usleep

PHP

Home Menu