A CAPTCHA should be familiar to any web user. Those small squiggly words that you generally need to input to verify your identity on contact pages for example. What many users don't know however is where those words come from and just how that data is being used. In this Google ReCaptcha tutorial we'll explain all the ReCaptcha basics and show you how to get this security standard up and running on your website.
What is reCaptcha?
The term CAPTCHA was coined in 2003 and refers to a "Completely Automated Public Turing test to tell Computers and Humans Apart". In order to prevent spam and fight bots, these tests are placed where form submissions are required (messages or comments) and are used to prevent progress until the test is passed. These tests are generally viewed as the slightly skewed letters people see on websites, but the newer version like the recaptcha example image included works as a concise pop-up.
ReCaptcha was a project spearheaded by Luis Von Ahn at Carnegie Mellon University, with the aim of digitizing historical text with this same CAPTCHA function. While users would see the spam prevention technique just like any other Captcha, the function of translating old books and articles into digital text can be achieved behind the scenes.
The Benefits of Using ReCaptcha
In covering the reCaptcha basics, we need to focus on the brilliant aspect of ReCaptcha that we just mentioned, the words are not generated randomly. They're pulled from scans of old text. The targeted libraries of text has grown with time, but all of the original book pages are being digitally scanned then transformed into simple text using "Optical Character Recognition" (OCR). The user submission are then used to confirm that OCR result. It's extensively human proofreading of automated transcription.
This technology was subsequently purchased by Google in 2009 and it's audience was expanded to reach thousands of web developers. Google claims that "200 million CAPTCHAs are solved by humans around the world every day", which is an astounding amount. The success of ReCaptcha project has established it as one of those rare "two birds with one stone" instances that works to achieve a philanthropic even as we speak.
Using ReCaptcha with PHP Projects
<html> <body> <form method="post" action="verify.php"> <?php require_once('recaptchalib.php'); $publickey = "your_public_key"; echo recaptcha_get_html($publickey); ?> <input type="submit" /> </form> </body> </html>
Once you've flushed out your page, you just need to include your custom public key and you're good to go. What goes inside the form itself is obviously up to you, but if you'd like to see a fully flushed contact form CodeForGeek has a solid tutorial on the subject. Since all forms are unique it's worth mentioning that there are several additional methods spelled out on Google Developer and their Github page. When you submit the form, the script activates and the user's response gets verified. You can also see a stripped down ReCaptcha example of the newer ReCaptcha v2 Demo which illustrates the functionality of a ReCaptcha submission form very clearly.
ReCaptcha Not Working - What Do I Do?!?!
We didn't go into too much depth on using recaptcha with php, because most integrations are pretty unique. There are really only a couple points that must be accurate in order to get your ReCaptchas working properly. Since we've built quite a few websites with contact forms, we can show you the most common issues when you've got ReCaptcha not working.
- Is Your Form Working? This sounds obvious, but your first step of troubleshooting should be to ensure your form submits w/o using ReCaptcha as a security deterant.
deferto see if that solves the issue.
- Common Code Snags. Make sure you've included the proper key (no spaces before/after parenthesis) and be sure you've whitelisted the domain you're currently using recaptcha with.
- Browser Specific Issues. Make sure you're not using a browser that blocks external scripts by default (Firefox for example). Take your security walls down momentarily to make sure you're getting an accurate reading.
- Still Not Working? Check out Google's Troubleshooting Documentation for more info.