Skip to content

Instantly share code, notes, and snippets.

@hexathos
Created November 18, 2012 01:15
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hexathos/4102410 to your computer and use it in GitHub Desktop.
Save hexathos/4102410 to your computer and use it in GitHub Desktop.
Create UniqueID in php
<?php
function genUUID($prefix=null,$maxlength=36)
{
$s = strtoupper(
hash(
'whirlpool',hash('sha1',
microtime(true).crypt(
uniqid(
rand(),
true)
)
)
)
);
$guidText =
substr($s,0,8) . '-' .
substr($s,8,4) . '-' .
substr($s,12,4). '-' .
substr($s,16,4). '-' .
substr($s,20,$maxlength);
return $prefix.$guidText;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment