As much as everyone hates those weird shaped characters, trying to figure out what it says so we can copy, we all hate spam too. ReCaptcha does a great job of creating “Captchas” for those spammers. In this article, I am going to explain how you can implement their API to your PHP based website. They do a great job of explaining it on their website on other programming languages too if you would like to take a look, its right here.
First off, you need to go here and get an account. After you finish your sign up, you come to a page where you register your domain.
You don’t need create multiple accounts for multiple domains, all you need to do is check the checkbox right under your domain name.
Next, you get to this page with your API keys. Note those API keys since you are going to use them in your implementation. Obviously, mine are covered right now :)
Anyways, then you can either click “reCAPTCHA plugins and libraries” and figure out how to implement it yourself or read the rest of this post :) They do have explanations on ASP.Net and more if you use a different language on your website. You can have different programming languages on different sites and still use the same API keys by the way.
Next, you need to download the library from here and then upload it to your server. Now open the page where you post something, anything really.. that you want the reCaptcha to show up and enter the following code;
<?php
require_once('recaptchalib.php');
$publickey = "Your public API key"; // you got this from the signup page
echo recaptcha_get_html($publickey);
?>
Note: You can put the first two lines in your global include file and then use the last line for the captcha to show up anywhere.
Now, open the page where you get the data from your form. Before you do any checks (e.g. Check empty fields, or email address validation), you want to check the captcha.
So include the following code in the beginning of your file;
<?php
require_once('recaptchalib.php');
$privatekey = "Your private API key";
$resp = recaptcha_check_answer ($privatekey,
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]);
?>
And where you want the check to happen include the following code;
<?php
if (!$resp->is_valid) {
echo "The reCAPTCHA wasn't entered correctly. Go back and try it again.";
}
?>
That’s it. You should be able to run the code now. Let me know, if you run into any problems and I will try to help.
Thank you for the information. I appreciate it. You have a very well-done blog.
I usually don’t leave comments!!! Trust me! Though I enjoyed your blog site…especially this post! Would you mind terribly if I threw up a backlink from my web site to your blog site?
Absolutely not, I’d be happy.
I agree with everything that was posted in this article, I
Hello.. I want to subscribe to your blog but I cannot find your rss link, please help. Thanks. – Jen
You can access the RSS feed through this link – http://www.weblimner.com/feed/rss/
I guess I should put a link up on the website.
Thank you so much for your help. The very best. Man, this thing’s getting better and better as I learn more about it.
blog did exactly what you said it does. Your site is great to work with. I can’t say enough about blog.
Good Post. Can you email me back, please. Awaiting your Answer.
What did you send? I didn’t get any emails.
hi
Hi how are you i really liked this.
This is my first time i visit here. I found so many interesting stuff in your blog especially its discussion. From the tons of comments on your articles, I guess I am not the only one having all the enjoyment here! keep up the good work.
Great article. There’s a lot of good data here, though I did want to let you know something – I am running Mac OS X with the current beta of Firefox, and the layout of your blog is kind of bizarre for me. I can read the articles, but the navigation doesn’t function so great.
I have just tested it and it looks pretty fine to me. Can you take a screenshot if its no hassle please?