Forum Moderators: coopster
$im = ImageCreate(200, 25);
$white = ImageColorAllocate($im, 255, 126, 40);
$black = ImageColorAllocate($im, 212, 212, 212);
srand((double)microtime()*1000000);
/*Runs the string through the md5 function*/
$string = md5(rand(0,9999));
/*creates the new string. */
$new_string = substr($string, 17, 5);
/*fill image with black*/
include ('mysql.php');
if ($_SESSION['new_string']!= $random2) {
$notice = "<div id=\"failure\">Image Verification Failed.</div>";
echo "New String :". $_SESSION['new_string'];
echo "Input : $random2";
ImageFill($im, 0, 0, $black);
/*writes string */
ImageString($im, 10, 75, 5, $new_string, $white);
header('Content-type: image/png');
ImagePNG($im, "verify.png");
ImageDestroy($im);
?>
This script of mine works very well when i run it for the very first time,ie, when the session has no data in it. But once i submit the form, the data is assigned to session. And I want that data to change everytime, the user submits. Please Help.
though I guess if you are using a timestamp it could just test that and if it is too old then show an expired message, no use storing them at all
as for expiration, you could have a cron clean up links, or have them in a db and scour them from there every so often
there are a ton of ways you could do it