PHP GUID generation functions and classes

Source: Internet
Author: User
Tags chr md5 rand uuid

  This article mainly introduces the use of PHP to generate GUIDs, using functions and classes to generate GUIDs, detailed description of what is the GUID, the advantages of GUIDs, and so on, the need for friends can refer to the following

First, the GUID profile GUID: That is, the globally unique Identifier (globally unique identifier) is also known as the UUID (universally unique Identifier). A GUID is a binary length 128-bit numeric identifier generated by a specific algorithm that indicates the uniqueness of the product. GUIDs are primarily used to assign identifiers that must be unique in a network or system that has more than one node or multiple computers. On Windows platforms, GUIDs are widely used in Microsoft's products to identify objects such as registry entries, class and interface identities, databases, system directories, and so on. The GUID is formatted as "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", where each x is a 32-bit hexadecimal number in the range 0-9 or a-f. For example: 6F9619FF-8B86-D011-B42D-00C04FC964FF is a valid GUID value. Second, the advantages of the GUID 1.GUID in space and time is unique, to ensure that the same time different places produced different numbers.   2. No duplicate GUID values are generated for any two computers in the world. 3. When the GUID is required, it can be automatically generated by the algorithm, without the need of an authoritative agency to manage it.   4.GUID is fixed in length and relatively short, and is ideal for sorting, labeling, and storage. Third, the GUID generation function   code is as follows: function Create_guid () {    $charid = Strtoupper (MD5 (Uniqid (Mt_rand (), true));     $hyphen = CHR//"-"     $UUID = CHR (123)//"{"    . substr ($charid, 0, 8). $hyphen   & nbsp. substr ($charid, 8, 4). $hyphen     substr ($charid, 4). $hyphen    . substr ($charid, 4). $h Yphen     substr ($charid, 20,12)     CHR ($);//"}"     return $uuid; {  III, GUID generation class PHP Get GUID class: guid_class.php   code as follows: <?php     class System     {        function Currenttimemillis ()         {            list ($ USEC, $sec) = Explode ("", Microtime ());             $sec. substr ($usec, 2, 3);        }         class netaddress     {        V Ar $Name = ' localhost ';         var $IP = ' ';         function getlocalhost ()//static         {        &N Bsp   $address = new netaddress ();             $address->name = $_env["COMPUTERNAME"];             $address->ip = $_server["Server_addr"];             return $address;        }        function toString ()         {            return St Rtolower ($this->name. /'. $this->ip);        }     {    class Random     {        FUNCT Ion Nextlong ()         {            $tmp = rand (0,1)? -':'';             $tmp. RAND (1000, 9999). RAND (1000, 9999). RAND (1000, 9999). Rand, 999. R and (100, 999);        }     {   //three    //A microsecond paragraph is an address segment is a random number     class Guid     {        var $valueBeforeMD 5;         var $valueAfterMD 5; &nbs P       function Guid ()         {            $this->get Guid ();        }        //        function GetGuid ()         {            $address = Netaddress::getloca Lhost ();             $this->valuebeforemd5 = $address->tostring (). ': '. System::currenttimemillis (). ': '. Random::nextlong ();             $this->VALUEAFTERMD5 = MD5 ($this->valuebeforemd5);        }         function NewGuid ()         {    & nbsp       $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);        }     &nbsP   GUID class use method:   Code as follows: require_once ("guid.class.php");     $Guid = new Guid ();     Print $Guid->tostring ();  
Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.