A PHP captcha script, requiring users to enter in a code from an image to verify that they are human and not a spam bot.
easycaptcha.php displays the image, and sets a cookie. The cookie is an MD5 hash containing:
1. Replace "OASDOIJQWOIJDASDOI" in captcha/easycaptcha.php, and the code snippets below, with a different secret code.
2. Copy the captcha directory into the directory which contains the code you want to protect.
3. Copy the two code snippets below into the appropriate places. One snippet shows the captcha image, the other snippet
validates the captcha hash.
Input captcha: Insert this code into the registration/comment form, where you want the user to view the image and enter the captcha code in.
print '<img src="captcha/easycaptcha.php" /> <br />Enter code from above image: <input type="text" name="confirm_code" />';
Validate: Insert this code whenever you want to make sure the user can go no further if they haven't entered the captcha.
if (empty($_REQUEST['confirm_code']))
{
die("Confirm code not given.");
}
else
{
if ( isset($_COOKIE['Captcha']) )
{
list($Hash, $Time) = explode('.', $_COOKIE['Captcha']);
if ( md5("OASDOIJQWOIJDASDOI".$_REQUEST['confirm_code'].$_SERVER['REMOTE_ADDR'].$Time) != $Hash )
{
die("Captcha code is wrong.");
}
elseif( (time() - 5*60) > $Time)
{
die("Captcha code is only valid for 5 minutes.");
}
}
else
{
die("No captcha cookie given. Make sure cookies are enabled.");
}
}
View the source of the sample used in this page.
The source below contains instructions on how to use EasyCaptcha with phpBB2
EasyCaptcha source