Welcome Guest, Not a member yet? Register   Sign In
Problems with captcha due to microtime() php funcion

captcha plugin uses microtime() funtion to generate the image and other things, but microtime() php funcion only works in operative systems that support the gettimeofday() system call.

Then, in some scenaries captcha doesn't work.

some idea to fix it?

-Lots of thanks-

Hi again,

I think the problem is solved. I have used mt_rand funcion to generate $usec and $sec variables that uses the captcha instead microtime(). I don't know if I will have collateral problems because captcha save in $now variable the current date using $usec and $sec. It can be a temporal solution for people with the same problem.

The code (it's a bit faster than before!:

$usec = mt_rand(0,99999999);
$usec = $usec/ 100000000;
$sec = mt_rand(0,9999999999);
//Old version
//list($usec, $sec) = explode(" ", microtime());

$now = ((float)$usec + (float)$sec);

We can also detect when $usec and $sec are not setted and in this case use mt_rand

Another solution (maybe a little better)

Use time() function to retrieve the $sec variable and mt_rand() to generate $usec variable

$sec = time();
$usec = mt_rand(0,99999999);
$usec = $usec/ 100000000;

echo "SEC ".$sec." USEC ".$usec;

Collateral problems? Someone knows?

Theme © iAndrew 2016 - Forum software by © MyBB