Posted By

brownrl on 01/26/15


Tagged

uuid guid


Versions (?)

GUID / UUID


 / Published in: PHP
 

URL: http://www.itsgotto.be/cv

A simple uuid generator for PHP. checks if there is already one.

  1. /**
  2.  * Defines the guid function
  3.  *
  4.  * @category functions
  5.  * @package skeleton
  6.  * @author Rob Brown <[email protected]>
  7.  * @license http://www.gnu.org/philosophy/free-sw.html GPL Free
  8.  * @link http://www.itsgotto.be/cv.php
  9.  */
  10.  
  11. /**
  12.  * Generate a uuid
  13.  *
  14.  * Generate a UUID taken from a web page that said this was the way to do it.
  15.  *
  16.  *
  17.  * @return string A uuid
  18.  */
  19. function guid() {
  20. if (function_exists('com_create_guid')) {
  21. return trim(com_create_guid(), '{}');
  22. } else {
  23. mt_srand((double) microtime() * 10000); //optional for php 4.2.0 and up.
  24. $charid = strtoupper(md5(uniqid(rand(), true)));
  25. $hyphen = chr(45); // "-"
  26. $uuid = ''//chr(123)// "{"
  27. . substr($charid, 0, 8) . $hyphen
  28. . substr($charid, 8, 4) . $hyphen
  29. . substr($charid, 12, 4) . $hyphen
  30. . substr($charid, 16, 4) . $hyphen
  31. . substr($charid, 20, 12)
  32. . ''; //chr(125);// "}"
  33. return $uuid;
  34. }
  35. }

Report this snippet  

You need to login to post a comment.