Wednesday 7 December 2011

How to Make a User Enter a Captcha Before Redirecting

How to Make a User Enter a Captcha Before Redirectingthumbnail A captcha is an effective way to cut down on spam email and message postings. The increasing amount of personal and financial information on the World Wide Web has made it an attractive target for unscrupulous marketers and criminals. A large number of groups operate “spiders” or “bots,” which are programs that travel through the web; they can be used to harvest personal information such as email addresses, post unwanted advertising messages in blogs, or create accounts for various purposes.

One way to stop these programs is by using a “captcha”, which is a simple word or pattern recognition test that the user must pass to continue. Captchas are designed to be easy for humans to solve but difficult for computers, thus making automated use of these sites difficult. By far the most popular captcha program is Google’s free reCAPTCHA. For others, see the links in the Resources section.

Difficulty:ModerateAdministrative access to your sitePHP language supportAn HTML editor1

Visit recaptcha.net and create an account (or sign in with a Google account if you have one). Click “Add Site”, enter your site’s domain name, and click “Create Key” to obtain public and private keys. Make a note of these keys, or leave the page up in your browser; you will be using them to communicate with Google’s reCAPTCHA server.

2

Download the PHP reCAPTCHA library from the Google Code site listed in the References section below.

3

Unzip the PHP reCAPTCHA library and place the file “recaptchalib.php” into the folder on your site that includes the page with your form.

4

Open your HTML editor and create a file called “verify.php”.

5

Put the following code at the top of “verify.php”:

In the third line above, replace “your_private_key” with the private key you obtained in Step 1. Leave the quote marks in place. Toward the bottom, in the “else” section, place the code that you will use to redirect the user after the test. Save the file.

6

Open the page on which your form appears in your HTML editor.

7

Create a new

In the fourth line above, replace “your_public_key” with the public key you obtained in Step 1. Leave the quote marks in place.

8

Save the file. reCAPTCHA should now be working.

The Google Code site in the References section includes a complete guide to the reCAPTCHA plugin.

The public and private keys must be entered accurately (cutting and pasting is best). Do not confuse them, or the test will not work.

Your form needs to be set up to get its variables with $_POST rather than $_REQUEST.

Photo Credit Medioimages/Photodisc/Photodisc/Getty Images


Find Out More...!

No comments:

Post a Comment