img verification script - session problem in IE
Posted: Mon Jul 03, 2006 6:59 am
Hi, I've just written an image verifcation script in PHP for a site I'm building, it generates a random 6 digit number, stores this in a session variable, creates an image from the string and is then called to the form page by 'img src=verif.php'. For some reason when using IE the random number in the session variable changes every few seconds so that by the time the form has been submitted the number that was entered doesn't match the session var. No prob in firefox, netscape or opera. The code is as follows:
I'm really tearing my hair out over this so any help greatly appreciated.
Carlos
Code: Select all
<?php
session_start();
srand(microtime() * 1000000);
$secur = rand(100000,999999);
$_SESSION['secur']=$secur;
$newImg = imagecreate(135,40);
$bg = imagecolorallocate($newImg,255,255,255);
$textcolor = imagecolorallocate($newImg,rand(0,100), rand(0,100), rand(0,255));
$bgnoise=1;
while ($bgnoise<15)
{
$a=rand(0,135);
$b=rand(0,40);
$c=rand(0,135);
$d=rand(0,40);
$lincol1=rand(160,255);
$lincol2=rand(215,255);
$lincol3=rand(190,255);
$linecolor=imagecolorallocate($newImg,$lincol1,$lincol2,$lincol3);
imagefilledrectangle($newImg,$c,$d,$a,$b,$linecolor);
$bgnoise++;
}
$font = imageloadfont("v3.gdf");
imagestring($newImg, $font, 10, rand(5,15), substr($secur,0,3) , $textcolor);
imagestring($newImg, $font, 70, rand(5,15), substr($secur,3,6) , $textcolor);
imagefill($newImg,0,0,$bg);
header ("Content-type: image/gif");
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
$newImg = imagerotate($newImg, rand(-10,10), 0);
imagegif($newImg);
imagedestroy($newImg);
?>Carlos