Posted By

assbach on 07/29/07


php random String unique id uuid uid rand

Versions (?)

Who likes this?

1 person have marked this snippet as a favorite


simple UUID

 / Published in: PHP


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  


RSS Icon Subscribe to comments
Posted By: zermok on March 31, 2019


You need to login to post a comment.