Created
November 27, 2015 01:04
-
-
Save Teino1978-Corp/805afc31dc59813f8cf3 to your computer and use it in GitHub Desktop.
A GUID (globally unique identifier) is a bigger, badder version of this type of ID number. You may see the term UUID tossed about (universally unique identifier), a nitpicky word for those whose numbers are unique not only within the globe, but throughout the entire universe. - http://guid.us/GUID/PHP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PHP | |
Its easy to make GUIDs in PHP. Below is clean code using windows COM to get GUIDs. When the PHP creates GUIDs or UUIDs they are V4 guids. | |
$guid = com_create_guid(); | |
echo $guid; | |
If you are not a on windows based platform you can roll this code for making GUIDs in PHP: | |
function getGUID(){ | |
if (function_exists('com_create_guid')){ | |
return com_create_guid(); | |
}else{ | |
mt_srand((double)microtime()*10000);//optional for php 4.2.0 and up. | |
$charid = strtoupper(md5(uniqid(rand(), true))); | |
$hyphen = chr(45);// "-" | |
$uuid = chr(123)// "{" | |
.substr($charid, 0, 8).$hyphen | |
.substr($charid, 8, 4).$hyphen | |
.substr($charid,12, 4).$hyphen | |
.substr($charid,16, 4).$hyphen | |
.substr($charid,20,12) | |
.chr(125);// "}" | |
return $uuid; | |
} | |
} | |
To use the above functon: | |
$GUID = getGUID(); | |
echo $GUID; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment