Jump to content

GD Image Verification Question


calabiyau

Recommended Posts

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); 


Link to comment
https://forums.phpfreaks.com/topic/38910-gd-image-verification-question/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.