PHP – Random ID Generator
Posted by elg3ne on 10 Mar 2008 8:37 am. Filed under Scipts & Tutorials.
<?php
//set the random id length
$random_id_length = 6;
//generate a random id encrypt it and store it in $rnd_id
$rnd_id = crypt(uniqid(rand(),1));
//to remove any slashes that might have come
$rnd_id = strip_tags(stripslashes($rnd_id));
//Removing any . or / and reversing the string
$rnd_id = str_replace(".","",$rnd_id);
$rnd_id = strrev(str_replace("/","",$rnd_id));
//finally I take the first 10 characters from the $rnd_id
$rnd_id = substr($rnd_id,0,$random_id_length);
$today = date("mdy");
#echo "Random Id: $today$rnd_id";
$random_req_id=("$today$rnd_id");
?>
//set the random id length
$random_id_length = 6;
//generate a random id encrypt it and store it in $rnd_id
$rnd_id = crypt(uniqid(rand(),1));
//to remove any slashes that might have come
$rnd_id = strip_tags(stripslashes($rnd_id));
//Removing any . or / and reversing the string
$rnd_id = str_replace(".","",$rnd_id);
$rnd_id = strrev(str_replace("/","",$rnd_id));
//finally I take the first 10 characters from the $rnd_id
$rnd_id = substr($rnd_id,0,$random_id_length);
$today = date("mdy");
#echo "Random Id: $today$rnd_id";
$random_req_id=("$today$rnd_id");
?>
Note: I did not write this script. I just found it on the web. I’m just sharing the script. I used it once on my page.
Thank you.