Home › Forums › CSS › Nice Simple Contact Form › Re: Nice Simple Contact Form
February 25, 2009 at 10:19 am
#54296
davesgonebananas
Member
I use reCaptcha for spam prevention. Simply sign up for an API key at http://recaptcha.net/ and download the reCaptcha PHP library from http://recaptcha.net/plugins/php/
To add the reCaptcha to the contact form you simply add the following code (must be a .php file):
Code:
Then to verify the captcha you add the following before the email is processed:
Code:
require_once(‘recaptchalib.php’);
$privatekey = “…”; // you got this from the signup page as well
$resp = recaptcha_check_answer ($privatekey,
$_SERVER[“REMOTE_ADDR”],
$_POST[“recaptcha_challenge_field”],
$_POST[“recaptcha_response_field”]);
$privatekey = “…”; // you got this from the signup page as well
$resp = recaptcha_check_answer ($privatekey,
$_SERVER[“REMOTE_ADDR”],
$_POST[“recaptcha_challenge_field”],
$_POST[“recaptcha_response_field”]);
if (!$resp->is_valid) {
die (“The reCAPTCHA wasn’t entered correctly. Go back and try it again.” .
“(reCAPTCHA said: ” . $resp->error . “)”);
}