com_create_guid()函数在服务器端出现错误,但在本地使用php可以正常工作 [英] com_create_guid() function got error on server side but works fine in local using php
本文介绍了com_create_guid()函数在服务器端出现错误,但在本地使用php可以正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
正在努力在php文件中生成一个GUID.我正在使用com_create_guid()
.在localhost上工作正常,但我在远程服务器上显示以下错误.
working on generate a guid in a php file.i'm using the com_create_guid()
. It works fine on localhost but i shows the below error in remote server.
致命错误:在第6行调用未定义的函数com_create_guid()
Fatal error:Call to undefined function com_create_guid() on line 6
我的代码是(指导部分)
my code is(guid part nly)
$guid = com_create_guid();
echo $guid;
任何想法
推荐答案
您可以手动创建GUID:
You can create GUIDs manually:
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 = 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;
关注:
http://php.net/manual/en/function. com-create-guid.php
这篇关于com_create_guid()函数在服务器端出现错误,但在本地使用php可以正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文