Encodera

Thanks for reading!

Donate to the site — we work hard for you.

PHP reference

uniqid

Returns an identifier based on the current time.

Syntax

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

Parameters

ParameterTypeDescription
$prefixstringOptional. The beginning of the identifier.
$more_entropyboolOptional. `true` adds extra characters.

Return value

stringA string of 13 characters.

Examples

An identifier — different on every run:

<?php
 
echo uniqid('order_');

The length without a prefix:

<?php
 
echo strlen(uniqid());

Output:

13

Notes

The identifier is predictable — it is built from the time. Use random_bytes() for tokens and secret links.

See also

  • random_bytes — Returns cryptographically secure random bytes.
  • time — Returns the current timestamp.

Related recipes

In the tutorial

  • Strings — Working with strings in PHP — quotes, concatenation, length, searching, replacing and multibyte functions.

Thanks for reading!

Donate to the site — we work hard for you.