Definition
A universally unique identifier (UUID) is a 128-bit number used to identify information in computer systems. The term globally unique identifier (GUID) is also used. When generated according to the standard methods, UUIDs are for practical purposes unique, without depending for their uniqueness on a central registration authority or coordination between the parties generating them, unlike most other numbering schemes. While the probability that a UUID will be duplicated is not zero, it is close enough to zero to be negligible.
Format
In its canonical textual representation, the sixteen octets of a UUID are represented as 32 hexadecimal (base 16) digits, displayed in five groups separated by hyphens, in the form 8-4-4-4-12
for a total of 36 characters (32 alphanumeric characters and four hyphens). For example:
123e4567-e89b-12d3-a456-426655440000
xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx
PHP Functions
The following function will generate v4 UUID
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
function gen_uuid() { return sprintf( '%04x%04x-%04x-%04x-%04x-%04x%04x%04x', // 32 bits for "time_low" mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ), // 16 bits for "time_mid" mt_rand( 0, 0xffff ), // 16 bits for "time_hi_and_version", // four most significant bits holds version number 4 mt_rand( 0, 0x0fff ) | 0x4000, // 16 bits, 8 bits for "clk_seq_hi_res", // 8 bits for "clk_seq_low", // two most significant bits holds zero and one for variant DCE1.1 mt_rand( 0, 0x3fff ) | 0x8000, // 48 bits for "node" mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ) ); } |
Test the functions
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
for ($i = 0; $i < 10; $i++) { echo gen_uuid() . "\n"; } // OUTPUT /* 4b0b138c-b0e8-49ef-a88d-0252555b50af 0fddfe3b-a2c3-45e0-8c13-c3ef9b345f20 d8567de3-eab1-49a3-8d26-b085a18ffc24 87dbb446-701a-4e5e-988d-e585ab04a5eb 5b10f3ac-b1bd-4042-abd8-b0208513d589 69680784-4e8f-47ea-984d-87eae9978215 39acac61-5f21-45ed-9dae-72b426c1c676 6ac52b79-37bd-44b6-b891-bccc523c7172 2323855e-2499-437d-8016-6eb07df28374 d84fee55-bcf1-4670-9924-d2342926be0e */ |
Hiya, I’m really glad I have found this info. Nowadays bloggers publish just about gossips and net and this is actually frustrating. A good site with interesting content, that is what I need. Thanks for keeping this web-site, I’ll be visiting it. Do you do newsletters? Cant find it.