Page 1 of 1

Using Recaptcha to your registration form Rate Topic: -----

#1 felixtgomezjr  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 3
  • View blog
  • Posts: 68
  • Joined: 04-November 09

Post icon  Posted 14 November 2009 - 03:46 AM

Have you seen website registration page lately? See that image where there are texts, words, alphanumeric or phrase that you need to type? That is what we called CAPTCHA (Completely Automated Public Turing test to tell Computers and Humans Apart). Before, if you want to incorporate captcha into your page, you have to make some functions in php to convert your string into an image. And you have to enable image functions of PHP to generate the image. Not this time! No more hassle. Just use reCAPTCHA.

reCAPTCHA is a free, secure and accessible CAPTCHA implementation. Today let us talk on how to incorporate reCAPTCHA to your registration page. I assume that you already know how to make a registration form and that the current task that you are going to do right now is just to integrate reCAPTCHA.

To start with, you have to create a reCAPTCHA account. Follow this link. Once you have created your account, type the domain name. You can choose the “Enable this key on all domains (global key)” if you will be using the key for several domain/websites.

Click the CREATE KEY button. You have to remember your public and private key because you will be using that one in your code. Before we will go back to your code, download this recaptcha library.

Now back to your code. Supposing you have
<form name=”form1″ method=”post” action=”testformsave.php”>
First name: <input type=”text” name=”firstname” id=”firstname”>
Last name: <input type=”text” name=”lastname” id=”lastname” />
<input type=”submit” name=”cmbsubmit” id=”cmbsubmit” value=”Submit”>

Insert this code after the Last Name line

$publickey = “”;
echo recaptcha_get_html($publickey);

See to it that the library is on the same path as your registration page. The $publickey should contain the key that you have from reCAPTCHA.

Once that is done, go to your page that handles the form submitted. Let us say you have all ready the script that will save registrant’s data to your database. You can see my other tutorial here. All you have to do is to inject on the top the

$privatekey = ” “;
$resp = recaptcha_check_answer ($privatekey,$_SERVER["REMOTE_ADDR"],$_POST["recaptcha_challenge_field"],

if (!$resp->is_valid)
die (”The reCAPTCHA wasn’t entered correctly. Go back and try it again.” . “(reCAPTCHA said: ” . $resp->error . “)”);
put your code here.

The $privatekey variable should contain the key given to you by reCAPTCHA. Thats it! You have made your registration page as spam-free as possible.

Happy coding

Is This A Good Question/Topic? 0
  • +

Replies To: Using Recaptcha to your registration form

#2 webmin  Icon User is offline

  • D.I.C Regular

Reputation: 4
  • View blog
  • Posts: 256
  • Joined: 21-May 08

Posted 06 January 2011 - 01:33 PM

Ok so looking at that form its simple enough to see how you do that, but if I'm not mistaken that page must be a php page correct? (Or at least it should be because its not recommended to force php to work in html) My question is this? My page is html only, and it would be a royal pain to change it to be otherwise. So how would that work? Can I make it validate in the form processor script?

This is the exact page I'm working with: My Home Page. Any suggestions would be great. Thanks

Update: No worries. I managed to solve this on my own. Thanks Though

For those of you wondering the answer to this question, I was infact able to just place the code I needed in my form processor without any change to my html file.

This post has been edited by webmin: 06 January 2011 - 04:17 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1