php学习--生成guid

+展开
-PHP
class System
{
function currentTimeMillis()
{
list($usec,$sec)=explode(" ",microtime());
return $sec.substr($usec,2,3);
}
}
class NetAddress
{
var $Name='localhost';
var $IP='127.0.0.1';
function getLocalHost()
{
$address=new NetAddress();
$address->Name=$_ENV["COMPUTERNAME"];
$address->IP=$_ENV['SERVER_ADDR'];
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()
{
$this->getGuid();
}
function getGuid()
{
$address=NetAddress::getLocalHost();
$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);
}
}


function getGuid()
{
   $GUID=new Guid();
   return $GUID->toString();
}

加支付宝好友偷能量挖...


原创文章,转载请注明出处:php学习--生成guid

评论(0)Web开发网
阅读(101)喜欢(1)PHP/apache/Perl