Posted By

assbach on 07/29/07


Tagged

php random String unique id uuid uid rand


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

ocool


simple UUID


 / Published in: PHP
 

URL: http://en.wikipedia.org/wiki/Uuid

create a random string like a UUID. this will do the job in most cases. usage: uuid(); # creates a string of 32 chars uuid(4); # creates a string of 4 chars uuid(32); # creates a string of 32 chars uuid(150); # creates a string of 32 chars

  1. function uuid($length=32) {
  2. mt_srand((double)microtime()*1000000);
  3. $r = strtoupper(md5(time().$_SERVER["REMOTE_ADDR"].$_SERVER["UNIQUE_ID"].mt_rand(0,9999)));
  4. if ($length<32){ $r=substr($r,0,$length-1); }
  5. return $r;
  6. }

Report this snippet  

You need to login to post a comment.