您好,欢迎访问一九零五行业门户网

php生成全球唯一标识符guid的算法示例

本文介绍下,php生成全球唯一标识符guid的例子,有需要的朋友参考下。1,创建php类库文件-guid.php
name = $coumputer_name; $address->ip = $ip; return $address; } function tostring() { return strtolower($this->name.'/'.$this->ip); }}class random { function nextlong() { $tmp = rand(0,1)?'-':''; return $tmp.rand(1000, 9999).rand(1000, 9999).rand(1000, 9999).rand(100, 999).rand(100, 999); }}class guid{ var $valuebeforemd5; var $valueaftermd5; function guid($computer_name, $ip){ $this->getguid($computer_name, $ip); } //by bbs.it-home.org function getguid($coumputer_name, $ip){ $address = netaddress::gethost($coumputer_name, $ip); $this->valuebeforemd5 = $address->tostring().':'.system::currenttimemillis().':'.random::nextlong(); $this->valueaftermd5 = md5($this->valuebeforemd5); } function newguid() { $guid = new guid(); return $guid; } function tostring() { $raw = strtoupper($this->valueaftermd5); return substr($raw,0,8).'-'.substr($raw,8,4).'-'.substr($raw,12,4).'-'.substr($raw,16,4).'-'.substr($raw,20); }}?>
2,调用示例,生成唯一的gid:
tostring();//输出结果:3238d32e-807c-b1c4-01c4-fd1346d32110?>
其它类似信息

推荐信息