Session variables not working for CAPTCHA function?
Posted: Thu Feb 25, 2010 11:13 am
Hi all, I need a little help. I have a little form with a captcha image to prevent abuse. It's not working properly. The password is generated just fine, and the captcha image is displayed just fine, but when I go to check the password against the response there is nothing in the $_SESSION["passwd"] value that I set. For readability I'll do some pseudo-code so you can see if I'm doing something obviously wrong.
Code: Select all
// captcha.php - make a password, store it as a session variable, create and show the the captcha image
session_start();
$passwd = generate_a_password();
$_SESSION["passwd"] = $passwd;
header("Content-Type: image/jpeg");
$image = generate_captcha_image($passwd);
imagejpeg($image);
exit();
Code: Select all
// form.php - show the captcha image and accept user input
echo "<form action=\"process.php\" method=\"post\"><img src=\"captcha.php\"><br><input type=\"text\" name=\"response\"><input type=\"button\" value=\"submit\"></form>";
Code: Select all
// process.php - check if the response is the same as the password we generated
session_start();
if ($_GET["response"] != $_SESSION["passwd"])
{
echo "incorrect response.";
}
else
{
echo "correct response!";
}