21 Aug 2012

How to Add Captcha to Your Website

How to Add Captcha to Your Website
How to Add Captcha to Your Website
By Bogdan Marius Ionescu

Adding a captcha box to your site is extremely easy! Here's the how-to.
There are some options on choosing captcha implementations out there, I tried the reCaptcha. So here it is:

1st Step: get your personalized key
First of all, visit the recaptcha.net site and sign up specifying your sites for access. Here you can assign keys for your websites.It's 100% free!
2nd Step: add the code
In this article I'll present a PHP example. reCaptcha comes also for .net, classic asp, java/jsp, perl etc.
The implementation has 2 parts - these lines to the posting form:
require_once('recaptchalib.php');
$publickey = "your_public_key"; // you got this from the signup page
echo recaptcha_get_html($publickey);
These lines make a beautiful customizable(css) insert containing the actual captcha box.
Secondly - to finish the verification, on the server side - the script which is supposed to take over what your form posted and verify if the entered captcha code is valid, add these lines:
require_once('recaptchalib.php');
$privatekey = "your_private_key";
$resp = recaptcha_check_answer ($privatekey, $_SERVER["REMOTE_ADDR"], $_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]);
if (!$resp->is_valid) {
// not a valid captcha code entered, display error
} else {
// valid captcha code entered, go on with the post
}
Who should use this?
Well my first thought is to the web sites which offer the possibility for an unregistered user to insert comments, upload files, in general to ad content.
Why?
Because there can be someone who could spam your web site and the next day when you check it up you see it full of garbage or maybe even worse - down due to maximum disk space quota. Moreover you could have "the luck" your site is crawled by some very important bosts i.e. Google, Bing etc when it contains all that garbage - if you don't manually validate the user input and suddenly your page rank could drop due to garbage content.
How does it work?
The code you have to enter is displayed as an image. Moreover, the writing in the image contains different character fonts, displayed in general in different axis rotation and having different color. some of the implementations use additional layers over the text like different ink splatter layers, strike throughs, symbols. These are there in order to confuse automatic detectors (like OCR ones for example) when trying to guess the actual text and automatically add it in the verification box. No automation means less chances of spamming.
For the most recent news, distributions, and all supported programming languages please visit the Google Developers page for reCaptcha at:
https://developers.google.com/recaptcha/docs/php
http://centraladvisor.com
http://www.google.com/recaptcha/learnmore
Article Source: http://EzineArticles.com/?expert=Bogdan_Marius_Ionescu
http://EzineArticles.com/?How-to-Add-Captcha-to-Your-Website&id=7205688

Share:

0 comments :

Post a Comment

Friends, feel free to share your honest opinions about this post. Thank you.