Guid. Class. php file
PHP code
<? PHP
Class System
{
Function currenttimemillis ()
{
List ($ USEC, $ Sec) = explode ("", microtime ());
Return $ sec. substr ($ USEC, 2, 3 );
}
}
Class netaddress
{
VaR $ name = 'localhost ';
VaR $ IP = '1970. 0.0.1 ';
Function getlocalhost () // static
{
$ Address = new netaddress ();
$ Address-> name = $ _ env ["computername"];
$ Address-> IP = $ _ server ["server_addr"];
Return $ address;
}
Function tostring ()
{
Return strtolower ($ this-> name. '/'. $ this-> ip );
}
}
Class random
{
Function nextlong ()
{
$ TMP = rand (0, 1 )? '-':'';
Return $ TMP. Rand (1000,999 9). Rand (1000,999 9). Rand (1000,999 9). Rand (100,999). Rand (100,999 );
}
}
// Three paragraphs
// Segment is microsecond segment is address segment is random number
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 );
}
}
?>
UsePHP code
<?php require_once("guid.class.php"); $Guid = new Guid(); print $Guid->toString(); ?>