CW Web Solutions Logo
"Web Design, Web Development, Security and Internet Marketing"
Projects
Projects

PHP GUID Class

Friday, January 22, 2010

CreateGUID.class.php
strResult;

**********************************/

class CreateGUID {
   var $strResult;
   function CreateGUID() {
      // Create array of 22 case sensitive hexidecimal charaters
      $strHexDecimal = array("a","b","c","d","e","f","A","B","C","D","E","F",
	  "0","1","2","3","4","5","6","7","8","9");
      
      // Loop through the first 8 characters, then seperate with a hyphen
      for($i=1;$i<=8;$i++) {
         $strGUID = $strGUID . $strHexDecimal[array_rand($strHexDecimal)];
      }
      $strGUID = $strGUID . "-";
      
      // Loop through 4 characters 3 times, seperating with a hyphen
      for($i=1;$i<=3;$i++) {
         for($n=1;$n<=4;$n++) {
            $strGUID = $strGUID . $strHexDecimal[array_rand($strHexDecimal)];
         }
         $strGUID = $strGUID . "-";
      }
      
      // Loop through the last 12 characters
      for($i=1;$i<=12;$i++) {
         $strGUID = $strGUID . $strHexDecimal[array_rand($strHexDecimal)];
      }
      // Example of returned output: 9AE1aCE4-25E1-11Dd-272a-3aAC64Eec3A3
      $this->strResult = $strGUID;
   }
}
?>
sample.php
strResult;
?>
Bookmark and Share
Comments
You can make comments without registration. All comments are moderated. Click the Comment link at bottom of the page to open the comment form.
Make a Comment
CW Web Solutions LLC, an Atlanta based company
2009 Copyright Pending