天天看點

php 生成guid_PHP 生成 Guid - 開啟 COM 元件使用 com_create_guid() 方法

使用com_create_guid()在 php 檔案中可以生成 guid,但需要配置 com_dotnet 才能使用。

确定 php\ext 目錄中已經下載下傳好了 php_com_dotnet.dll,如果沒有網上下載下傳個,php7、php5.6 都已經内置了,隻是沒開啟。

開啟方法:

修改 php.ini 檔案兩個位址,修改後如果是 IIS 需要重新開機:

;extension=php_com_dotnet.dll 把前面的;注釋号去掉,如果沒有這行自己添加,weiku.co

;com.allow_dcom = true 把前面;注釋去掉,設定為 true

運作 phpinfo() 檢視:

php 生成guid_PHP 生成 Guid - 開啟 COM 元件使用 com_create_guid() 方法

Linux 不支援 com 的 Guid 生成相容方式:

function getGUID(){

if (function_exists('com_create_guid')){

return strtolower(trim(com_create_guid(), '{}')); //去大括号轉小寫,weiku.co

}

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;