Call to undefined function uuid_create() in php

0 votes
I am getting error as "Call to undefined function uuid_create()" in php. Even i tried com_create_guid() function to create guid but it is not working on my server.
asked Jan 28, 2013 by inquirer (710 points)
    

1 Answer

+1 vote
 
Best answer

 

It belongs to uuid extension, may be it is not enabled on your server. Better you can use your own function to create guid. Here is an example:

function NewGUID()
{
   $guidstr = "";
   for ($i=1;$i <= 16;$i++) {
      $b = (int)rand(0,0xff);
      if ($i == 7) { $b &amp;= 0x0f; $b |= 0x40; } // version 4 (random)
      if ($i == 9) { $b &amp;= 0x3f; $b |= 0x80; } // variant
      $guidstr .= sprintf("%02s", base_convert($b,10,16));
      if ($i == 4 || $i == 6 || $i == 8 || $i == 10) { $guidstr .= '-'; }
   }
   return $guidstr;
}

 

answered Jan 28, 2013 by analyst (3,200 points)
selected Jan 28, 2013 by inquirer
...