for($i=0,$ii=1;$i<$_POST['no_of_coupon']; $ii++) {
$unique_code=uniqid();
$category_unique_code = substr($unique_code,rand(0,strlen($unique_code) - 6),6);
$i++;
echo $category_unique_code;
}
$_POST['no_of_coupon']
is the no . For eg. if user want 1 lakh coupon code or more i.e. $_POST['no_of_coupon']
, all the code is inserted into the the database and the code is unique but I have tried above method , but its not unique then i tried another method
function gen_random($length=32)
{
$final_rand='';
for($i=0;$i< $length;$i++)
{
$final_rand .= rand(0,9);
}
return $final_rand;
}
for($i=0,$ii=1;$i<$_POST['no_of_coupon']; $ii++) {
$unique_code=gen_random(6);
$category_unique_code = substr($unique_code,rand(0,strlen($unique_code) - 6),6);
$i++;
echo $category_unique_code;
}
This method is also not generating unique coupon code , I just need 6 to 8 digit unique no So somebody have any idea to generate unique no , please tell me