Generate the Guid use for php class
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | < ?php class System { function currentTimeMillis() { list($usec, $sec) = explode(" ",microtime()); return $sec.substr($usec, 2, 3); } } class NetAddress { var $Name = 'easemarry.com'; var $IP = '69.65.10.199'; 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, 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).'_'.time(); } } ?> |
If you enjoyed this post, please consider to leave a comment or subscribe to the feed and get future articles delivered to your feed reader.


Comments
No comments yet.
Leave a comment