The UUID full name is the universally unique identifier, which is an identifier that can be generated using any computer, without requiring a central database for management, which guarantees that there is little chance of duplication. The range of the UUID is said to assign a UUID to every grain of sand in the world, and there is no repetition.
Recently in the code to change WordPress, need to use UUID. However, there is no function in PHP to generate the UUID, so you have to write one yourself.
1 2 3 4 5 6 7 8 9 10 11 |
if (!function_exists (' Com_create_guid ')) {function Com_create_guid () {return sprintf ('%04x%04x-%04x-%04x-%04x-%04x %04x%04x ', Mt_rand (0, 0xFFFF), Mt_rand (0, 0xFFFF), Mt_rand (0, 0xFFFF), Mt_rand (0, 0X0FFF) | 0x4000, Mt_rand (0, 0X3FFF) | 0x8000, Mt_rand (0, 0xFFFF), Mt_rand (0, 0xFFFF), Mt_rand (0, 0xFFFF)); } } |
The above code can generate a UUID version 4. The UUID currently has 5 versions, of which the fourth edition is completely random and easy to generate. And the Com_create_guid, is a function of PHP in Windows, it directly calls the COM CreateGUID function to generate the UUID, but in Linux does not have the corresponding function library, had to write their own. To facilitate use on different platforms, a function with the same name is created. The other code is to generate random numbers.
As for usage, call Com_create_guid () directly.