I want generate an account ID ,total user account less than 500K,so i want make account ID as short as possible, so I want know how to generate 8 or 16 characters ID use php ?
Asked
Active
Viewed 7,080 times
2
-
refer https://stackoverflow.com/questions/2040240/php-function-to-generate-v4-uuid – Dinesh undefined May 30 '17 at 05:05
-
2Possible duplicate of [PHP function to generate v4 UUID](https://stackoverflow.com/questions/2040240/php-function-to-generate-v4-uuid) – Lepidopteron May 30 '17 at 07:20
1 Answers
10
Try this
echo strtoupper(bin2hex(openssl_random_pseudo_bytes(16)));
This will generate 16 characters unique string
You can create common function also
function GUID() {
return strtoupper(bin2hex(openssl_random_pseudo_bytes(16)));
}
$id = GUID();
echo $id;

Nidhi
- 1,529
- 18
- 28
-
4
-
1use `8` instead of `16` ---- `strtoupper(bin2hex(openssl_random_pseudo_bytes(8)));` will generate `16` characters – 风声猎猎 May 20 '21 at 06:40