Skip to content

Instantly share code, notes, and snippets.

@helicoder
Created January 26, 2017 09:31
Show Gist options
  • Save helicoder/5fcbf5d301939167a6c6febf7e229e42 to your computer and use it in GitHub Desktop.
Save helicoder/5fcbf5d301939167a6c6febf7e229e42 to your computer and use it in GitHub Desktop.
PHP Function to return a Global Unique Identifier (GUID or UUID)
// Returns a Global Unique Identifier
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 = substr($charid, 0, 8).$hyphen
.substr($charid, 8, 4).$hyphen
.substr($charid,12, 4).$hyphen
.substr($charid,16, 4).$hyphen
.substr($charid,20,12);
return $uuid;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment