Skip to content

Instantly share code, notes, and snippets.

@drwebman
drwebman / guid.php
Created Jan 26, 2017
PHP Function to return a Global Unique Identifier (GUID or UUID)
View guid.php
// 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