I am currently putting the finishing touches on my website before going fully live later. I am having an amazingly irritating issue with my CAPTCHA on the sign up form. Here is the code for the CAPTCHA:
and here is the snippet of code from the script that checks the CAPTCHA:
where $md5captcha = md5($imgverify), where $imgverify = the POST var of the text field that contains the CAPTCHA value to match against the real one. Every time I run this script, it fails, and I get a nice red message on my test page proclaiming "The letters and numbers you entered did not match the verification image." What I would like is to have some ideas as to why this script is constantly failing.
My server details:
All GD libraries are there;
My session handling funcions are custom-made to insert session data into a MySQL database;
I have checked the session handling functions using a test script and it worked fine.
I have checked the MySQL db for the session data and it is there, I have even copied the exact (non-md5) value of the CAPTCHA and put it into the field so I know the problem cannot just be me mistyping everything. Thank you in advance!
Matt
Code:
<?php
require('includes/sessions/sessionfunc.php');
session_start();
$alphanum = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
$rand = substr(str_shuffle($alphanum), 0, 5);
$image = imagecreatefrompng("formbg.png");
$textColor = imagecolorallocate ($image, 0, 0, 0);
imagestring ($image, 5, 5, 8, $rand, $textColor);
$_SESSION['img_code'] = md5($rand);
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");
header('Content-type: image/png');
imagepng($image);
imagedestroy($image);
?>
and here is the snippet of code from the script that checks the CAPTCHA:
Code:
if($md5captcha != $_SESSION["img_code"])
$errors[] = "The letters and numbers you entered did not match the verification image.";
where $md5captcha = md5($imgverify), where $imgverify = the POST var of the text field that contains the CAPTCHA value to match against the real one. Every time I run this script, it fails, and I get a nice red message on my test page proclaiming "The letters and numbers you entered did not match the verification image." What I would like is to have some ideas as to why this script is constantly failing.
My server details:
All GD libraries are there;
My session handling funcions are custom-made to insert session data into a MySQL database;
I have checked the session handling functions using a test script and it worked fine.
I have checked the MySQL db for the session data and it is there, I have even copied the exact (non-md5) value of the CAPTCHA and put it into the field so I know the problem cannot just be me mistyping everything. Thank you in advance!
Matt