php get guid,PHP 生成 Guid 唯一码

PHP 生成 Guid 唯一码

ifu25 • 2021 年 04 月 16 日

在微软的技术平台上有 Guid 唯一码,号称能保证全球唯一,在 Windows 平台上 PHP 生成唯一码可以借助 com_dotnet 的com_create_guid()来实现。

PHP 生成 Guid 唯一码方法

确定 phpext 目录中已经下载好了 php_com_dotnet.dll,如果没有网上下载个,php7、php5.6 都已经内置了,只是没开启。

修改 php.ini 文件两个地址:;extension=php_com_dotnet.dll 把前面的;注释号去掉

;com.allow_dcom = true 把前面;注释去掉,设置为 true

重启 IIS 运行 phpinfo()查看。

Linux 不支持 com 的兼容方式function getGUID(){

if (function_exists('com_create_guid')){

return strtolower(trim(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;

}

}

使用:$GUID = getGUID();

echo $GUID;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值