PHP中全局唯一标识符的GUID

时间:2017-02-16 12:37:48

标签: php mysql phpmyadmin mysql-workbench

如何在php中创建GUID

1-guid代表全局唯一标识符,通常用于在php中创建随机唯一字符串,在php中创建访问令牌

2 - 主要使用GUID生成访问令牌,生成唯一ID,在php中生成唯一字符串。使用本文如何在php中创建指南,您可以创建一个随机字符串,以保持唯一

3-GUID仅由字母数字字符组成,并按照连字符分隔的五个组分组,如下例所示:

3F2504E0-4F89-11D3-9A0C-0305E82C3301

例如: -

<?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;
}
}
?>

输出: $ GUID = getGUID(); echo $ GUID;

0 个答案:

没有答案