Using PHP, what are some ways to generate a random confirmation code that can be stored in a DB and be used for email confirmation? I can\'t for the life of me think of a wa
private function generateCodeSecurity()
{
list($usec, $sec) = explode(" ", microtime());
$micro = usec + $sec;
$hoy = date("Y-m-d");
$str = str_replace('-','',$hoy);
return rand($str, $micro);
}
With this little code, you can generate a random number, with a range of 7 to 11 numbers.
Using php functions:
Rand ();
Microtime ()
$hoy = date("Y-m-d");
$str = str_replace('-','',$hoy);
echo $str;
result date: 20170217
list($usec, $sec) = explode(" ", microtime());
$micro = usec + $sec;
echo $micro;
result micro varaible: 1487340849
Passing parameters in this function:rand ();
rand($str, $micro);
and return;
example:
list($usec, $sec) = explode(" ", microtime());
$micro = usec + $sec;
$hoy = date("Y-m-d");
$str = str_replace('-','',$hoy);
$finalresult = rand($str, $micro);
echo $finalresult;
result: 1297793555
I think it is difficult to repeat this number, for the reason it will never be the same day, nor the same hour, nor the same milliseconds of time.