Add reCAPTCHA to a form

You may have seen those funny squigly words on contact forms that you have to fill out before you can submit them. Those in general are refered to as reCAPTCHA fields and they're easy to add, once you know what to do and how they work. For a quick introduction please look here.

1) Get your private/public key pair:

Go to the signup page and get your public and private keys!

2) Add this javascript snippet to the page the form will be on:

<script type="text/javascript" src="" </script> <noscript> <iframe src="" height="300" width="500" frameborder="0"></iframe><br> </noscript> *fill in YOUR_PUBLIC_KEY with the one from the signup process

3) Include the recaptchalib.php in the page where the user will enter their guess.

 <form method="post" action="verify.php">
     $publickey = "YOUR_PUBLIC_KEY"; // you got this from the signup page
     echo recaptcha_get_html($publickey);
   <input type="submit" />
*fill in YOUR_PUBLIC_KEY with the one from the signup process

4) Add the code to check if it's correct in the form that's submitted before doing whatever else with it. Using the example above we would call this php file verify.php

 $privatekey = "YOUR_PRIVATE_KEY";
 $resp = recaptcha_check_answer ($privatekey,
 if (!$resp->is_valid) {
   // What happens when the CAPTCHA was entered incorrectly
   die ("The reCAPTCHA wasn't entered correctly. Go back and try it again." .
        "(reCAPTCHA said: " . $resp->error . ")");
 } else {
   // Your code here to handle a successful verification
*fill in YOUR_PRIVATE_KEY with the one from the signup process