How to create GUID in php
1-guid stands for globally unique identifier generally used to create random unique strings in php, create access token in php
2-Mostly use of GUID for generating access token, generate unique id, generating unique string in php. Using this article how to create guide in php you can create a random string for any use to keep unique
3-GUID consists of alphanumeric characters only and is grouped in five groups separated by hyphens as seen in this example:
3F2504E0-4F89-11D3-9A0C-0305E82C3301
Eg:-
<?php
/**
* Generate Globally Unique Identifier (GUID)
* E.g. 2EF40F5A-ADE8-5AE3-2491-85CA5CBD6EA7
*
* @param boolean $include_braces Set to true if the final guid needs
* to be wrapped in curly braces
* @return string
*/
function generateGuid($include_braces = false) {
if (function_exists('com_create_guid')) {
if ($include_braces === true) {
return com_create_guid();
} else {
return substr(com_create_guid(), 1, 36);
}
} else {
mt_srand((double) microtime() * 10000);
$charid = strtoupper(md5(uniqid(rand(), true)));
$guid = substr($charid, 0, 8) . '-' .
substr($charid, 8, 4) . '-' .
substr($charid, 12, 4) . '-' .
substr($charid, 16, 4) . '-' .
substr($charid, 20, 12);
if ($include_braces) {
$guid = '{' . $guid . '}';
}
return $guid;
}
}
?>
Output: $GUID = getGUID(); echo $GUID;