Please i need help on how to generate highly unique id for my php program, i have one which is doing that but after about 190 unique numbers it started to repeat itself which is making the unique column in the database problematic. please here is my code code if there is something i did wrong please help me correct it thanks. " function uniqids() {
$chars = "003232303232023232023456789";
srand((double)microtime()*1000000);
$i = 0;
$pass = '' ;
while ($i <= 7) {
$num = rand() % 33;
$tmp = substr($chars, $num, 1);
$pass = $pass . $tmp;
$i++;
}
return $pass;
}
$finalcode='RS-'.uniqids();
"
Kesavan KrishnanPosted May 29, 2017, 1:06 AM
Mohammed AdamuPosted May 30, 2017, 6:28 AM
Kesavan KrishnanPosted May 30, 2017, 1:52 AM
for($i = 0; $i<100; $i++){
$unique[$i] = md5(uniqid(mt_rand(), true).microtime(true));
echo $unique[$i].PHP_EOL;
}
print_r(array_diff($unique, array_unique($unique)));
?>
Mohammed AdamuPosted May 29, 2017, 12:18 PM
Mohammed AdamuPosted Feb 20, 2017, 11:26 PM
Bryian TanPosted Feb 20, 2017, 10:24 PM
Mohammed AdamuPosted Feb 20, 2017, 10:02 PM
$num = rand(1000000, 99999999) %33; i have added it but i think it still generating but what is the assurance that it will not repeat itself. Thanks a lot.Bryian TanPosted Feb 20, 2017, 9:52 PM
$num = rand(1000000, 99999999) %33;