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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.