uniqid
Returns an identifier based on the current time.
Syntax
uniqid(string $prefix = "", bool $more_entropy = false): stringParameters
| Parameter | Type | Description |
|---|---|---|
| $prefix | string | Optional. The beginning of the identifier. |
| $more_entropy | bool | Optional. `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:
13Notes
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.