captcha help
Posted: Mon Jan 14, 2008 2:06 am
Hi, ive got the following script that doesnt work:
here's the captcha.php referenced in the form above:
basically, it doesnt seem to work, the session information generated by captcha php is different than the session info on the main file. can anyone help?
thanks
Code: Select all
<?php
session_start();
if (isset($_POST["submit"]))
{
if (($_POST["captcha"]) != ($_SESSION["key"]))
{
die("Error: You must enter the code correctly");
}
else
{
echo "Success!";
}
}
?>
<form name="contact" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<label for="name">Name:</label></td>
<input type="text" name="name" />
<label for="company">Company:</label>
<input type="text" name="company" />
<label for="email">Email:</label>
<input type="text" name="email" />
<label for="message">Message:</label>
<textarea name="message" rows="6" cols="20"></textarea>
<img src="captcha.php" border="0"><?php echo $_SESSION["key"]; ?>
<input type="text" name="captcha" width="50px" />
<input type="image" src="images/submit.png" name="submit" />
</form>
here's the captcha.php referenced in the form above:
Code: Select all
<?php
session_start();
$md5 = md5(microtime() * mktime());
$string = substr($md5, 0, 5);
$captcha = imagecreatefrompng("captcha.png");
$black = imagecolorallocate($captcha, 0, 0, 0);
$line = imagecolorallocate($captcha, 233, 239, 239);
imageline($captcha, 0, 0, 39, 29, $line);
imageline($captcha, 40, 0, 64, 29, $line);
imagestring($captcha, 5, 20, 10, $string, $black);
$_SESSION["key"] = md5($string);
header("Content-type: image/png");
imagepng($captcha);
?>thanks