calabiyau Posted February 17, 2007 Share Posted February 17, 2007 I'm using the following code to generate a verification image and then checking it on the receiving page before sending out an email. Problem is, if user fills out the form and goes to processing page, then hits the back button and tries again, the whole thing breaks down. Next time they submit, a new random string has been generated but the verification image doesn't update, so the two won't match up when I check. I wouldn't think just hitting the back button on the browser would cause the script to re-execute and generate a new string. Can anyone see what i'm doing wrong here? /*register the session variable. */ session_register('new_string'); /*You will need these two lines below.*/ echo "<html><head><title>Verification</title></head>"; echo "<body>"; /* set up image, the first number is the width and the second is the height*/ //$im = ImageCreate(100, 30); $im = imagecreatefrompng('verification.png'); /*creates two variables to store color*/ $white = ImageColorAllocate($im, 255, 255, 255); $black = ImageColorAllocate($im, 0, 0, 0); /*random string generator.*/ /*The seed for the random number*/ srand((double)microtime()*1000000); /*Runs the string through the md5 function*/ $string = md5(rand(0,9999)); /*creates the new string. */ $sub_string = substr($string, 17, 7); $_SESSION['new_string'] = $sub_string; $background = 'verification.jpg'; /*fill image with black*/ ImageFill($im, 0, 0, $background); /*writes string */ ImageString($im, 4, 20, 10, $sub_string, $white); /* output to browser*/ ImagePNG($im, "verify.png"); ImageDestroy($im); Quote Link to comment Share on other sites More sharing options...
calabiyau Posted February 17, 2007 Author Share Posted February 17, 2007 Okay figured it out. Browser was caching the image, had to add a unique query string to the html image tag to force the browser to download the newly generated image. Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 17, 2007 Share Posted February 17, 2007 I normally use the time() as the query string cause it will never repeat. You can also add some no cache headers. Quote Link to comment Share on other sites More sharing options...
calabiyau Posted February 17, 2007 Author Share Posted February 17, 2007 Yes, time is exactly what I used as well. the no cache headers didn't work in this case though. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.