Get a Unique ID in PHP

Get a Unique ID in PHP

Use PHP to get a unique ID with the uniqueid() function.  Note that this method does not guarantee uniqueness, nor cryptographically-secure values.  Use more_entropy to increase uniqueness  See additional resources for more information.

echo ​uniqid(); //13-character string, like 61f8c79d8f1a2
echo uniqid(null, true); //23-character string, like 61f8cae10417a7.74045607

Description:

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

Additional Resources:

https://www.php.net/manual/en/function.uniqid.php

If you need cryptographically-secure or critical functionality, see these options:

 

Share this Post