Like most of you, I have had more than enough SPAM on my sites. One of the biggest sources is in the comments section. Let’s put an end to them now.
I have already shown you how to prevent spam bots from submitting stories by using the fabulous tool, reCaptcha, now let’s add it to the comment form as well.
To add it to your comment form, just do the following steps:
Download the latest reCaptcha library from here and upload to your “root”.
You will also need reCaptcha keys for your site, you will need to register and add your site to reCaptcha. Register for reCaptcha keys here.
Open comment_form.tpl, find:
<input class="log2" onclick="openSpellChecker(‘comment’);" name="spelling" type="button" value="{#PLIGG_Visual_Check_Spelling#}" />{/if}
After, add:
require_once(‘recaptchalib.php’);
$publickey = "ENTER PUBLIC KEY HERE";
$privatekey = "ENTER PRIVATE KEY HERE";
# the response from reCAPTCHA
$resp = null;
# the error code from reCAPTCHA, if any
$error = null;
# are we submitting the page?
if ($_POST["submit"]) {
$resp = recaptcha_check_answer ($privatekey,
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]);
if ($resp->is_valid) {
echo "You got it!";
# in a real application, you should send an email, create an account, etc
} else {
# set the error code so that we can display it. You could also use
# die ("reCAPTCHA failed"), but using the error message is
# more user friendly
$error = $resp->error;
}
}
echo recaptcha_get_html($publickey, $error);
{/php}
save. Thats it.
Here is the updated comment_form.tpl file with the reCaptcha code added. –
Comment Form (1.7 KiB, 74 hits)
This will eliminate all comments being left by spam bots and will also make human spamming less atractive as well.
If you use this module, leave me a comment below or perhaps think of linking back to http://www.pliggs.com
Be sure to follow me on Twitter as well for one on one help and news.






