For those who haven’t seen reCAPTCHA yet, it’s a script you can add to your site in form of a widget (for sites like blogs, forums, guestbooks, etc) and using some PHP on a regular site. What sets it apart from other CAPTCHAs out there is that the words the user identifies successfully, help digitize scanned books!
Their instructions for PHP aren’t very clear, and are obviously written for someone who knows exactly what they are doing. So I thought I’d make them a little more user-friendly (as opposed to coder-friendly).
Sign up
If you haven’t done so already, sign up at reCaptcha.com. Add a new site so that you can get your public and private keys for it. You can’t reuse the same keys for sites on other domains, so you have to add a new domain to your account to get a new set of keys.
Create Form and Process Files
When you create a contact form, you usually have 2 files: the form itself with the fields and the file with the script to send the form. We’ll call them form.php and process.php, respectively. If you have no idea what I’m talking about, learn how to make a contact form and the process file.
IMPORTANT: The tutorial I linked to above asks you to create feedback.html (or form.html) file, but we will need to change the extension to .php. Your form file MUST have the .php extension, not .html (or .htm), otherwise it will NOT work. So make sure both of your files end in .php.
Download the Files Needed
Download the reCaptcha library. You only need one file really (recaptchalib.php). The other ones are examples, readme and legal stuff – they don’t affect the functionality of your recaptcha.
Configuring the Form File
Now, open the form.php and add the following code.
Where and How?
Put this piece of code before the Submit button, where you want the CAPTCHA to appear. It needs to be enclosed in PHP tags because…well, it’s PHP.
What’s a public key and where do I get one?
It asks you to enter the public key. You can look this up by signing in and clicking on the registered site name.
<?php
require_once('recaptchalib.php');
$publickey = "..."; // you got this from the signup page
echo recaptcha_get_html($publickey);
?>
Notice that the require_once function in the example above expects the recaptchalib.php to be in the SAME directory as your form file. If it is in another directory, add that in. This works just like liking to pages on your site. So, for example if your recaptchalib.php is in directory called “captcha” that is on the same level as your form file, the function will look like this:
require_once('captcha/recaptchalib.php');
Configuring the Process File
We need to add the following code to the process.php file (or whatever file you are using to process the form). It has to be at the beginning of the file, before anything else, so keep that in mind (otherwise it’ll give you a warning about headers having been set already).
Notice that this code is asking for the private key, don’t confuse them, otherwise the captcha won’t work. You get that from the same page as the public key.
<?php
require_once('recaptchalib.php');
$privatekey = "...";
$resp = recaptcha_check_answer ($privatekey,
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]);
if (!$resp->is_valid) {
die ("The reCAPTCHA wasn't entered correctly. Go back and try it again." .
"(reCAPTCHA said: " . $resp->error . ")");
}
?>
This opens a blank page with the words after “die” if you enter the validation code incorrectly. Unfortunately, you can’t validate that with JavaScript, which according to reCAPTCHA support is not secure.
UPDATE: if you want to redirect to a different page instead of showing the default blank page, I explain how to do it over here.
Customization
What you can do though is customize the look. Enter the following JavaScript code in the <head> of your form.php file.
<script type= "text/javascript">
var RecaptchaOptions = {
theme: 'clean'
};
</script>
That strips all the formatting and just leaves the blue buttons, and looks like this:

And here’s a wiki page on how to style the blank box you now have. Not sure how you get rid of the blue buttons yet, but when and if I do, I’ll keep you updated.
This should get your captcha and your form up and running.
If you’re confused, leave a comment below
UPDATE: If you leave a comment and I don’t respond, please don’t take it personal, just a little too busy right now.
Thanks – great post!
Hi,
It is really wonderful post, I request you to please write this one for ASP.NET as well. I had a big discussion on ASP.NET forums for Catcha & ASP.NET forms with user create user wizard.
Please check that at : http://forums.asp.net/t/1199107.aspx may be useful.
Regards,
-Sunny.
Unfortunately, I only know how to do this in PHP and I haven’t used ASP before
I didn’t successfully include recaptcha on my form, I copy and paste the same thing, add the public key, private key and also replace the ‘REMOTE_ADDR’ with IP address. Did I miss something?
I create my form in html but using the php for the submit process. Do I need to have the form in php to get this working?
Regards,
Julia
Yes, the form must have the .php extension, otherwise it won’t work. Added this note to the post itself. Hope this helps.
Thanks. I found another source where it works with other type of Captcha. Here is the link http://identipic.com/.
hello,
thank you so much for creating this post! you’re right, the instructions on the reCaptcha website are very difficult to follow. i know you’re probably very busy, but I can’t find an answer anywhere. do you think you could take a look at my page with the captcha. i can’t get it to work correctly, and now the submit button is gone, do you have any suggestions? thanks, heather
http://finesocalhomes.com/guestbook.php
vera,
you are my hero!! thanks so much for your patience and help. the captcha is now showing up on my page! there are definitely still things i need to figure out, but at least it’s there! :]
a million thanks, heather
Love it, Thanks for making my life easier.
Can I still use this even though I don’t have my own server (I have space on a server)?
Is there a way to use the die statement to open a page (i.e. an error page that I make and add to my site) instead of just text?
Also thanks for this info, it makes a LOT more sense! (Especially because I don’t really understand PHP)
You can use it anywhere really.
Here’s how to specify a custom error page (line 9):
if(!$resp->is_valid) {
header("location:captcha_error.php");
die();
}
If you want to specify a “message sent” page if captcha was entered correctly, after the code above, add this:
else if($resp->is_valid) {
header("location:form_submitted.php");
}
If you are more familiar with php, you can redirect both of these to the same page and pass a variable along that would tell that page what text to display. For example, the code below will pass a variable to the page form-submitted.php called “result” and result will be set to true or false (or fail or pass) depending on whether the captcha was entered correctly. The code on the form-submitted.php page will retrieve that variable. If result was set to “fail” it will say that recaptcha was entered incorrectly, if result was set to “pass” it will say that the form was sent:
if (!$resp->is_valid) {
header("location:form-submitted.php?result=fail");
die();
}
else if ($resp->is_valid) {
header("location:form-submitted.php?result=pass");
}
In order to retrieve the value of the “result” variable, here’s what you need to add to form-submitted.php:
<?php
if (isset($_GET['result']))
{
$result = $_GET['result'];
}
if ($result == "fail" )
{
$content = “The CAPTCHA code was entered incorrectly. Please go back to enter the code and send your form. “;
}
else if ($result == "pass" )
{
$content = "Thank you. Your form has been submitted.";
}
?>
And one last thing: put the following line where you want the message to appear:
<?php echo $content; ?>
don’t know why everyone is so happy – seems to me you stress both our forms must be php – must end in “.php” – and then direct us to a site to learn how to write the forms that only shows how to write a “form.html”. Thereby leaving me as confused as I’ve been from the start.
What does everyone else know that I don’t?
Please send it to me, whatever it is: abrogard@yahoo.com
@abrogard
The site I sent you to tells you how to create the form.html (they call it feedback.html) because it doesn’t know that we are going to add PHP to that file later on. It tells you how to build a form and make sure it submits and calls the process (sendmail.php) file.
If you put php code into an html file it will print it out as plain text, that’s why the file extension needs to be changed to php so that the file will recognize it. All you have to do is change the extension from html to php. I guess, if it’s so confusing I’ll add a note to the post about that.
Did you get it to work at all?
Well I got that much of it to work. Renamed the file and, sure enough, it still works as an html file.
And I got the captcha to appear on my page.
But after inputting the right words all you get is a blank page and after inputting wrong words all you get is a blank page.
I don’t know what I’ve done wrong.
does anyone have the ability to see my error and tell me?
My site page is http://xyford.com/viewers.php – renamed ‘viewers’ from ‘feedback’ and given a ‘php’ extension instead of ‘html’ and you can view source to see what I’ve done there. It’s a very simple page.
the file you can’t see is feedback.php and I’ve put it up on the web so’s you can see what I’ve done with it. Followed instructions, I think, but it’s not working right…
It is at http://files.xyford.com/feedbackphp.txt
renamed as a text file so’s you can click on that link and it’ll open to the code.
If anyone can tell me where I’ve gone wrong I’ll much appreciate it – my site currently ain’t working
regards,
ab
Thank you so much for this info! Much better worded and explained than the CAPTCHA site. I’m still having issues understanding it (since I don’t know anything about PHP). I can’t get the CAPTCHA thing to show up. I edited and entered the code, as you specified, but I must be missing something. The public key and coding that goes with it goes in the form.php right before , and the private key and coding goes in process.php, right? Do I need to enter anything else of mine besides the public and private keys? Do I need to add anything into recaptchalib.php? If you could let me know, I would really appreciate it! Thanks!
Any ideas why i am getting this error?
http://www.kbkmarketing.com/mailer.php
Fatal error: Call to undefined function: recaptcha_check_answer() in /home/kbkmark/public_html/mailer.php on line 4
Ok, I got the CAPTCHA to show up so nevermind about that, but I’m not receiving any emails that tell me the information that was filled out in the form. The “sendemail.php” is only supposed to have the following code without any “” tags, right?
Anyone have any ideas as to why I might not be getting the emails? Any help is appreciated. Thanks!
Whoops, sorry, the code got cut out of my last post *tries again without use less than, greater than signs*
The “sendemail.php” is only supposed to have the following code without any “html” tags, right?
”
?php
$email = $_REQUEST['email'] ;
$message = $_REQUEST['message'] ;
mail( “amy@mydomain.com”, “Feedback Form Results”,
$message, “From: $email” );
header( “Location: http://www.mydomain.com/thankyou.htm” );
?
“
ei!
Thanks so much I’m using it now on our soon to launch project
http://preview.msmb.biz/thermophore/order-status.php
You have a great portfolio. Wish you all the success in the web design world.
- erwin
I’ve installed the code
in my form and the code
is_valid) {
die (“The reCAPTCHA wasn’t entered correctly. Go back and try it again.” .
“(reCAPTCHA said: ” . $resp->error . “)”);
}
?>
in the php page that sends it. I have also saved the rechaptchalib.php file in the same directory as the form. I don’t get a captcha image in the form. Although I do get the captcha error message when I submit the form. Any idea? Do I need more code? The reCaptcha site talks about recaptcha_get_html and recaptcha_check_answer functions.
thanks
Thanks you just saved me about 2 hours of frustration!
Great post! But I am having a problem. Even if I enter correct code, it says that the code is incorrect. I have followed the exact steps that you have mentioned. Can you please suggest what might be the problem? Thanks
my site is getting pounded by spam so I’m trying to implement captcha. I’ve followed your instructions and have the captcha box appearing on my guestbook page, but it doesn’t appear to be working correctly. I think I’m not sure which file to add the process file code to. can you help?
I’ve added the public key code to guestbook.php
my other files are:
gdform.php
guest.php
guestbook.html
can you help with my confusion? thanks
Thanks so much for this most useful and helpful post! I could not figure out how to do this from the help that they give on the reCAPTCHA website. I followed your lead here with no problems.
Thank you so much for taking the time to write these instructions. It made installing Captcha so easy. The site really could use some instructions like this.
One question? Any way to modify the distorted text in the reCaptcha widget? It is really hard to understand.
@Cindy No, you can’t modify the words.
Awesome! Thanks so much for the clear, easy instructions!
Hi
I tried to implement recaptcha a few months ago as our trade application and contact forms are getting a lot of spam:
trade.shtml is the form without recaptcha and the one I modified is trade_test_recaptcha.shtml which shows the recaptcha widget but doesn’t work as I didn’t do any php changes. I’ve made another attempt at it by creating php trade_new_recaptcha.php and I including the php in the process document (which I believe is create_account.php) but now the recaptcha widget isn’t showing and I’m sure there are other erros.
I think I am getting confused as to what php and what javascript goes where and also the fact that the rest of the form is validated with Javascript. Any help would be appreciated. Thanks.
Is there anyway you could post the process code WITH the addtional code for the custom error and thank you page? I can get it to work fine with the origional ‘die’ code, but when I add the code you provided for the custom error and message sent pages, I continually get error pages that say I have an unexpected ) or . or ” Every permutation I am adding or subtracting is just not working. Below is what I though I should have, but it must be wrong…
is_valid) {
header(“location:captchaerror.php”);
die();
“(reCAPTCHA said: ” . $resp->error . “)”);
}
?>
I think something got cut off my last post…
is_valid) {
header(“location:captchaerror.php”);
die();
“(reCAPTCHA said: ” . $resp->error . “)”);
}
?>
[...] but it supports WordPress, MediaWiki and more. If you need some assistance with the PHP set-up, here is a good tutorial. Posted in Coding RSS 2.0 | Trackback | [...]
Thank you. Your instructions are much clearer than the documentation provided by reCaptcha.
Thank you so much for the tutorial! I’ve used thesitewizard.com to create my php contact form and now I’ve got the reCaptcha working without any of it’s errors showing up. But now I have a problem: none of my email comments are coming through and after I fill out the form and reCaptcha and hit submit I am rdirected to my feedbackerror.html page (the one you get when you fill out something wrong in the form, not the reCaptcha).
Any ideas on what could be causing this?? I’m not sure where in the code I went wrong.
Thanks for the simple explanation.
I’m getting an error when I try to redirect it though:
Parse error: syntax error, unexpected ‘:’ in /home/content/g/g/i/ggilmore/html/form.php on line 9
The “line 9″ being referred to is:
header(”location:captcha_error.php”);
Any idea what is causing this? I guess this is the same problem that Christopher has (above).
The reason why my error above was occurring was due to the fact that I simply copy/pasted the text provided without looking at it closely.
You’ll notice here:
header(”location:captcha_error.php”);
that there are two ‘closing’ quotation marks. They need to be ” “, not ” ”. Hope that helps you too Chris!
Hi, I used your guideline and successfully implement reCaptcha codes. This is very easy tutorial. One this I like to mention that I used both .php and .html extensions with my contactus form and both are working fine, even my error page is in .html and that is also working without any problem.
My actual recaptcha pages are at this location (I did not finalized them yet)
http://www.jamiaislamia.org/contactus1.html
Thanks
Saleem
@Gray thanks for pointing it out, I went back and edited those notorious quotes in my comment to ascii for “, so when the next person copies the code it should work fine without editing.
@Saleem I’m not sure how you got the php include to work on an html page, but hey, more power to ya!
Thank you very much!
Without your step-by-step tutorial my client’s contact form would have never worked with re-captcha.
You have explained very nicely how to do this and I’m very impressed by the time you have taken to respond our concerns.
Thank you very, very much!
Andrea
Great tutorial! After two days and many hours, your explanation did the trick. Thank you!!!
Thanks, I think I understand this for email use and it is much better explained the at the reCaptcha website. But, because of spam, I need to add reCaptcha to a website form that Posts to a CGI script. It’s bignosebird.com postcard cgi script. And my Form submit code reads:
How can I get reCaptcha to work with that type of form, when it has to go to a process.php next, and I really need the results from the form submit to work with a CGI script for the results page to pull up? Or isn’t that possible?
@ inko9nito
thanks for all the insight u have been sharing…
I’ve set up reCaptcha on my site and it works fine with FF and IE7, however for some reason some odd display keeps happening with Safari for windows (using latest version 3.1.2 )…
The process works but for some reason on the confirmation page, on top of the normal confirmation text, it shows the reCaptcha box again with the following line of text underneath:
“Type the two words:Type the eight numbers:Incorrect. Try again”
This is pretty odd and it only does it with Safari for some reason… Any suggestions?
Here is the url:
http://www.seishinmusic.net/contactformpage.html
PS: the other thing is I only actually receive the completed form by e-mail in my inbox about once out of every 10 attempts… I was thinking maybe this is because reCaptcha doesn’t allow multiple form submissions from the same IP within a short time span to avoid flooding or something like that… Do you know if that might be the case?
If that is not the case, then this is definitely an issue I have to solve or else it means 9 out of 10 people are getting a confirmation that their form has been sent successfully but I’m not receiving them… Any suggestions would be very much appreciated. Thanks again for your help and insight.
Best regards,
dimitri
@dimitri I’m running the the developer version 4 (also win.), so it shows up fine for me. I think this is a problem you should email the recaptcha people about because this seems like a pretty serious glitch! I haven’t had problems not receiving emails after submitting. May be another thing you should clear with the recaptcha support.
@Linda I’m sorry, I haven’t had any experience with CGI scripts before
@inko9nito
Thanks for your swift reply… I’ve been testing it for the last 2 days and now the emails all seem to be arriving ok… so maybe it was just a temporary glitch… everything is now working fine with FF and IE7… the only issue remaining happens after submitting the form in Safari (goes through fine), for some reason the reCaptcha box reappears at the top of the confirmation page, above the confirmation text (where it shouldn’t of course) …
Maybe I should have the confirmation page be another independent php file instead of having the processing php file creating it ? Do you think that could be the reason it is messing up with Safari?
Here is the code:
………………………………………………………………
is_valid) {
die (“>> The VALIDATION CHARACTERS were not entered correctly. Please return to the Contact Form by pressing the back button of your browser and try typing the characters again. Please make sure there are no spelling mistakes when recopying the 2 words generated in the Captcha box at the bottom of the form. We apologize for the inconvenience, however this is a necessary step in order to limit SPAM automatically sent by ill-intentioned bots. >> Les CARACTERES DE VALIDATIONS n´ont pas été insérés correctement. Merci de retourner au Formulaire de Contact en appuyant sur le bouton qui permet de revenir en arrière dans votre navigateur et d´essayer d´insérer les caractères à nouveau. Veuillez vous assurer que vous ne faites aucune faute de frappe lorsque vous recopiez les 2 mots générés dans l’encadré Captcha au bas de du formulaire. Nous vous prions de nous excuser de cet inconvénient, mais ceci est une étape nécessaire pour lutter contre le SPAM envoyé automatiquement par des bots mal intentionnés.” .
“(reCAPTCHA said: ” . $resp->error . “)”);
}
/* Subject and Email Variables */
$emailSubject = ‘correct subject entered here’;
$webMaster = ‘correct email entered here’;
/* gathering data variables */
$nameField = $_POST['name'];
$emailField = $_POST['email'];
$phoneField = $_POST['phone'];
$professionField = $_POST['profession'];
$otherField = $_POST['other'];
$subjectField = $_POST['subject'];
$messageField = $_POST['message'];
$newsletterField = $_POST['newsletter'];
$body = <<<EOD
Name: $name
Email: $email
Phone number: $phone
Profession: $profession
Other: $other
Subject: $subject
Message: $message
Newsletter: $newsletter
EOD;
$headers = “From: $email\r\n”;
$headers .= “Content-type: text/html\r\n”;
$success = mail($webMaster, $emailSubject, $body, $headers);
/* results renderd as html */
$theResults = <<<EOD
Confirmation page – Your contact form has been sent. Thank you
>> Your Contact Form has been sent successfully. Thank you for your interest in our music. >> Votre Formulaire de Contact a bien été envoyé. Merci de l´intérêt porté à notre musique.
EOD;
echo “$theResults”;
?>
…………………………………………………………..
Thanks for your insight and tips on what maybe causing the problem with Safari…
Best regards,
dimitri
PS: I’ll try contacting the recaptcha people to ask them as well… thanks again
I may fall into the dense category, but I’m still having problems with the above. Maybe it’s because my ISP uses CGI (instead of PHP) scripts for sendmail. What I don’t see here (or anywhere) is a simple set of sample files that Just Work, as-is. Here’s what would be great to get:
All of the PHP, XML, and/or HTML files needed to send a simple web e-mail form (name, e-mail address, content field), and also show errors or success on landing pages. reCAPTCHA built in to gate sending the e-mail.
The only thing that should need customizing with the above would be styling via html/css and placing public/private keys for reCAPTCHA.
Do you have anything like this?
Thanks,
@akulavolk Do the sample files that come with the reCaptcha PHP Library not work for you?
thank you for this article! I spend my morning trying to figure out the instructions on the recaptcha page and was just about to throw up my hands and hire someone to do it for me when i found this post and got my contact form captcha’d and workin in about 15 minutes.
Thanks!!!
[...] view article [...]
Is there any way to make the reCaptcha box smaller? Nice tutorial — thanks!
I get an error code on line 11 that says Parse error: syntax error, unexpected T_ELSE. Can you please help:
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]);
if (!$resp->is_valid) {
die (“The reCAPTCHA wasn’t entered correctly. Go back and try it again.” .
“(reCAPTCHA said: ” . $resp->error . “)”);
else if ($resp->is_valid) {
header(“location:thank-you.php”);
}
?>
Thank you so much for this easy explanation!
Thanks so much for this psoting. Like Liz said, I was about to give up because the site’s instructions were just horrible and I worked at it for 3 days and couldn’t find how to get this to work for my website. THIS WAS WONDERFUL. It explained in very simply way on how to do this and I got my contact form to actually work now! Thanks again.
@Cindy I don’t know which one of those is line 11 but from just glancing at the code I think the problem might be the quotes. Go through and replace all quotes (when I paste code here in the comments wordpress converts them and makes the code unusable). Try that.
Sorry, I don’t know how to make it smaller (yet) but if you figure it out, please come back and share
Hi i found on the recaptchalib.php, on line 125,
here:
function recaptcha_get_html ($pubkey, $error = null, $use_ssl = false)
{
if ($pubkey == null || $pubkey == ”) {
die (“To use reCAPTCHA you must get an API key from http://recaptcha.net/api/getkey“);
}
if ($use_ssl) {
$server = RECAPTCHA_API_SECURE_SERVER;
} else {
$server = RECAPTCHA_API_SERVER;
}
$errorpart = “”;
if ($error) {
$errorpart = “&error=” . $error;
}
return ‘
‘;
}
you can change the size of the table, making the box smaller or bigger, whatever.
I tried changing the two instances in recaptchalib.php,where the code gives size values (300px high by 500px wide), but the size of the Recaptcha graphic does not change. My table’s borders are simply not wide enough to accommodate it, and I am loath to redesign the whole page (or, to be more accurate, the template that half a dozen pages are based on) just to use Recaptcha. Has anyone found a way to make it show up smaller?
I uploaded form.php and formprocess.php and of course the recaptchalib.php to the metrowestcert site. I get the form, but there is no image for anyone to read. Can you tell me where I’ve gone wrong on this?
TIA,
Ginny
hi
i m in big trouble, pls help me that i m already including recaptcha and its working fine but the problem arising in that when i entered the right key then this also said the captcha entered wrongly.so what i can do for that .
i m using Joomla1.5
Wonderful refresher. Thank you.
Good job. Your instructions really helped.
excellent tutorial!
Great Post! Very helpful!
Cheers!
I’ve managed to get it to work upon following your instructions the first time when my form called on a process file to function. But now that I am working on a new form that runs from within itself, where do I place the different keys and bits of code? I either get everything to show up fine but nothing gets validated, or I keep getting an error that the recaptcha wasn’t entered correctly meaning I have it too early in the form (ie in the very begining etc.)
When putting them all together like in the example it still doesn’t work because it’s obviously not cooperating with the join/submit button.
I am wondering if it’s because I have an $error variable in my self processing form as well? And if so should I change it in the recaptcha stuff or the form (the latter being incerdibly complicated now -_-)
Here’s the code if it helps :/
Join Fill out the form below to join this fanlisting. Please make sure you've read the <a href="rules.php" title="Rules" rel="nofollow">rules</a> and if you have a website, that you put a <a href="codes.php" title="Codes" rel="nofollow">link</a> back up to <strong></strong> before joining! If you do not provide a password, one will be automatically generated for you. If you wish to update your member information, please <a href="edit.php" title="Edit User Information" rel="nofollow">click here</a>. <strong>Error:</strong> Personal Information <input type="text" name="j[memberName]" value=""> Name Password Password (Again) <input type="text" name="j[memberEmail]" value=""> Email Address display email address hide email address <? } if( $_HIVEID['captcha'] ){ print " \n". " \n". " \n". " \n"; } ?> Membership Details Country <input type="text" name="j[memberURL]" value=""> URL <input type="text" name="j[memberCodeURL]" value=""> Code URL <input type="text" name="j[memberTxt1]" value=""> Site Name <input type="text" name="j[memberTxt2]" value=""> Site Description Comment Submit Join Thank you for your submission, </strong></strong>. You should be added in the next update.Man that totally butchered the code… the join form I am using is from this website;
http://skode.void-star.net/projects/vs.hive/
[...] Dealing with Bots Bots are those robots, or automatic programs sent out by people who spam your email, website, “contact us” page and comments areas. So you know those images in a box where you have to type the characters of the image before hitting the submit button for a form, and the image changes each time you use it? Those can help out with thos nasty little bots. I found reCAPTCH on some Author websites and I was like, “Hey, where they get that?” With some research I found it and it’s just something to help out with those party pooper Spammers. It was a bit complicated to install and the directions on the actual site doesn’t help much at all for us basic HTML users, but this site helped me out A LOT and helped me get it up and running. Installing eCAPTCHA with PHP [...]
Hey nice post. I got this working in a different way but nice to see an alternative. I have a problem with the form data being stripped when I return from a wrongly entered recaptcha. Does anyone know a workaround. i tried using a history jscript back button but it appears that after the first error with this method it kept saying it had not been entered correctly even when it had. The only way to get around this was refresh the page but of course the form data disappeared forcing a user to re-enter it all again.
Although I haven’t yet tested it, I have followed your clearly stated instructions to the letter…until that is, I reached the following in Customization:
“Enter the following JavaScript code in the of your form.php file.”
The problem is that I can’t find anywhere in the code…so am I to assume that you mean “at the top of the page”?
Laurie
PS Actually, I’m terrified to make any changes to my *.php files since I hired someone to create them in the first place and am only guessing about whether I’m even working in the correct files. My fear is that I will upload the changes and crash my site.
I don’t have anything named form.php but am messing with a copy of register.php instead. Likewise, I do not have a process.php file but rather something called post.php.
And one last thing: Although I followed the tutorial instructions for creating these two files…actually the test files to run on my computer which has php5 installed…but don’t have a clue where to go from there. The tutorial seems to assume knowledge of apache servers, etc on the part of neophytes like myself.
Anyway, would you recommend that I hire another programming geek to do this for me? I was really hoping to learn to do it myself, but I’m lost in a cloud here!
Thanks in advance,
Im getting this after form is submitted:
Warning: Cannot modify header information – headers already sent by (output started at /home/content/b/i/z/bizpark290w/html/recaptchalib.php:59) in /home/content/b/i/z/bizpark290w/html/gdform.php on line 41.
Line 41 on my .php form submission script is:
}
fclose($fp);
if ($landing_page != “http://”){
header(“Location: http://landexchanger.com/recaptchalib.php“.$_SERVER["HTTP_HOST"].”/$landing_page”);
} else {
header(“Location: http://”.$_SERVER["HTTP_HOST"].”/”);
}
I have no idea what it wants me to put here. I have tried everything from just the file to an actual webaddress. It began as http:// so I figured I needed to put the address of the file
@morgan this error usually comes up when your php script doesn’t start on the very first line of the document. Also, if you have any extra empty lines before or after <?php and ?> tags.
awesome tutorial!.. this worked for me perfectly. i played with just about every possibility from the given instructions on the recaptcha site..
thanks alot! take care
Your tutorial helps a lot but, being a newby, I’m hung up on some basic definitions and actions. Here’s what I’ve got:
(1) uploaded (via ftp) the ‘recaptcha’ files to the following location on my host server: gpoponline.com/wp-content/plugins/cforms/. I believe the ‘cforms.php’ file I find there is equivalent to the ‘forms.php’ your instructions refer to. (couldn’t find anything specifically labeled ‘forms.php’.
(2) pasted in the code lines (require_once …) per the reCaptcha (and your) instructions, just ahead of the ‘enter button’ code in this ‘cforms.php’ file.
(3) pasted a copy of ‘recaptchalib.php’ file into the same folder as ‘cforms.php’ is in.
(4) Have no idea where to look for the ‘process.php’ (or equivalent) file. Have no clue where to look for it (for all that I suspect it’s smugly hiding somewhere in my WordPress folders under some obscure name). So here I sit hoping some kind soul will set my feet on the path of enlightenment. What is my best hope of satisfying the ‘process.php’ requirement?
THANK YOU!!!!!!!!!!!
FINALLY I GOT RECAPTCHA TO WORK THATS TO YOU. I will be linking to your page from my blog…
Check out JFischWeb.com in a few days…
[...] The site that helped, THANK YOU!!!: http://inko9nito.wordpress.com/2007/12/12/installing-recaptcha-with-php/ [...]
@Dennis, you’re in luck! There is a special recaptcha plugin for wordpress users! No coding required. Check it out:
http://wordpress.org/extend/plugins/wp-recaptcha/
Ah … the site you cite [pls. excuse the corny 'homonymics'] (http://wordpress.org/extend/plugins/wp-recaptcha/)
is where I got my download. I wondered why my WordPress page seemed to have digested and implimented the ‘reCaptcha’ plugin even though I’d gotten high centered on the setup process. Thank you kindly for the feedback.
I am doing an email form with processing code in same page, having trouble making my captcha work, were should i put the processing code
I can’t get it to work (: I have one form which has both the input form and the processing on it. I think that may be the problem but don’t kow how to fix it. Before I installed the Captcha, it worked fine and I got the “sent.php” to give its message. Any help is so very much appreciated.
thanks,
Pia
I got the php process to work fine, except, the information from the form doesn’t get sent.
I don’t recieve an email with the form’s fields in it.
Please help,
thanks
I can’t seem to get the redirects to work properly. I would like it to re-ask for the captcha if wrong info is supplied or have it email redirect to a thankyou page if the response is correct.
I have tried many different ways but each has it’s own issues. I would be happy to email you the code and pages if that helps.
Thanks
Travis
I have zero knowledge of PHP, but I was able to get the captcha on the site and working, however I can’t get the email from the form. Here is my code, please help when you can.
(sendmail.php)
is_valid) {
die (“The reCAPTCHA wasn’t entered correctly. Go back and try it again.” .
“(reCAPTCHA said: ” . $resp->error . “)”);
}
?>
–
Thanks,
Kristan
hi capthcha is is soooooooooo
great
Thank you SOO much for this post!
After spending an endlessly frustrating day at ReCaptcha and not having succeeded in anything but getting totally confused and fuddled, I then followed up on YOUR instructions and had it up, running and modified in an hour.
Wow!
How can I apply Re-captcha for Chronoform or RSForm!. I am using Joomla 1.01 Version with PHP 5.2.4(without GD Support enabled).
Any detail step by step procedure would help.
Thanks
Abhi
Thanks for info. Very helpful!!
i installed the script but – captcha is not seen on the page. Nothing wrong but coulndt understand what the problem is…
I got the public and private keys for my web site(s).
I’ve followed your instructions (which were above me from the get go).
I’ve spent three weekends on this.
I can’t get it working.
Please help.
Has anyone had a problem with the reCAPTCHA failing everytime?
I followed these wonderful instructions one one form on the site and it works great. I then put the same code on another form on the site and no matter how many times I try the reCAPTCHA it fails.
If anyone has experienced this, please advise.
Thanks,
Lori
Hi,
I am using WYSIWYG Web Builder. I can get the CAPTCHA to show etc but not sure what to do as the form process is in the same page as the form itself. If i add the following to the form file it goes straight to the CAPTCHA error and not the form itself. So basically i got the CAPTCHA showing etc nicely but as the form process info is in the same file as the form page itself i dont know how i get around adding the code below without it brining the error straight upon the contact page loading. If you could help i would much appreciate it. Thank you, Mat.
is_valid) {
die (“The reCAPTCHA wasn’t entered correctly. Go back and try it again.” .
“(reCAPTCHA said: ” . $resp->error . “)”);
}
?>
My form is set up the same way. The process happens within the same code that has the form.
Was there a solution to this where you are not calling upon a second file to process the form?
Hi!
About the customization of reCaptcha… Is there anyway to change the messages that show up when the javascript is disabled? These messages are:
- “We need to make sure you are a human. Please solve the challenge below, and click the I’m a Human button to get a confirmation code. To make this process easier in the future, we recommend you enable Javascript.”
- “Type the two words”
- “I’m a Human”
These texts are fine for a website in english but when you use reCaptcha for a website in another language, it would be more user-friendly to translate these default messages…
Thanks for your attention
Hello there.
It’s really kool to find someone that can, and is willing to offer the caliber of help you have in this article. I spent a day trying to figure this out then I found your post and had it up and running in about 15 minutes … Ahhhhhhhhhhh!
Anyway, I noticed that others are having the problem that I am experiencing but you haven’t addressed it yet. Everything appears to be working but I don’t get any emails, it confirms or errors out great but it never sends the emails??? I have checked everything, the keys, email addresses and have everything in it’s appropriate place. BUT I notice that there is a place, it’s line 6 in my code, that reads $_SERVER["REMOTE_ADDR"]. I also notice that one person has an entry for $_SERVER as RECAPTCHA_API_SECURE_SERVER or RECAPTCHA_API_SERVER. The post wasn’t complaining about my problem but is there supposed to be input by me in that slot and if so is the RECAPTCHA_API_SERVER or RECAPTCHA_API_SECURE_SERVER a correct entry? I’m just grabbing at straws because, get this, I DON’T KNOW! Can you point me in the right direction? I hate to bother you online heroes with these piddly questions but I’ve tried everything else and if this is the right answer you might want to put that as an update in your article. It is my hope that even though I am asking for an answer that, maybe, just maybe I’m helping out a bit.
In any case I really do appreciate the work you’ve done here and hope that my encouragement strikes a good note with you.
Thanks
Boo
I have installed recaptcha (seemingly) according to the instructions and there are no error messages. However, if I leave the recaptcha entry-box blank or enter the wrong words intentionally, my “thank-you” page comes up and the e-mail is sent. In fact, spam-comments are still coming through. I have contacted the recaptcha support and all they says is API is not functioning by their servers (I have no idea what they mean and they do not explain). What to do?
By the way, if I leave out the required fields, which I have set, my error-page does come up, asking me to reenter (which is as it should be). But the recaptcha-field appears to be useless, at this point, and inoperable (although you can see the code and copy it, etc). Help? hanks.
I received the following cryptic message from recaptcha support:
Hi,
Your code is not using the results of reCAPTCHA validation to prevent sending the email.
- Ben
Well, DUH. OK, then what to do! They don’t tell you! I even had sent them a printout of the code and mentioned that I had been working on this for over 8 hours. Help!
Hmm, the only thing I can think of is that they may have changed the code… Are you copying and pasting my code or using the code from the files you downloaded?
Hello, I’m not sure if this reply is to my message, but I did everything from your post, made the two PHP files per the page you sent me to and so far the only thing I havn’t changed is the “REMOTE_ADDR”. I did try putting in my URL but that just gave me an error. I noticed that on the recaptcha page they didn’t reference doing anyting with the “
OOPS! wrong key …. I noticed on the recapthca page they didn’t reference doing anything with the “REMOTE_ADDR’ spot, just says “REMOTE_ADDR’? any clues?
Boo
REMOTE_ADDR doesn’t need to be changed. Maybe try to do the same stuff in the tutorial but using the code you download off their site? It’s been a while since I wrote the post, so I wouldn’t be surprised if they changed something.
Great tutorial.
Thanks man.
Hi, Inko. Yes, indeed, I downloaded and used the public-key and private key, just as instructed. I did not even know about this page until days and days later. The code from you, as well as from them, seems to be the same, at least to my eyes. I am really appreciative of being able to hopefully get some sensible help here, because, otherwise, I am at wit’s end!
I have juggled the code, placed it on top, as you suggested, in between and various other things. At least trying 100 times. Nothing helps. Maybe e-mail me and I could send my code to you?
Oh, here’s one thing. The support people told me to enter the following, which I did and which is somewhat different from yours. I tried previously:
require_once(‘http://www/mydomain/contact/recaptchalib.php’);
They said to switch to:
require_once(‘/home/www/mydomain/contact/recaptchalib.php’);
Which is where the original entry form and process form is, as well.
That seems to be the only difference, but neither keeps spam out.
Well, hello there …
I’ve tried everything .. I noticed that in your code you have a } on line 13, but when I try to put that code there I get this error:
Parse error: syntax error, unexpected ‘}’ in /homepages/43/d271701497/htdocs/tribune/sendmail.php on line 17
so, if you will look at this and give me a clue, here is the code in my processing file named “sendmail.php”
(I’ve tried to send you a copy of my code but the message keeps getting discarded?? Is there a way to send you the code?)
If you could give me clue on this problem, I’d be happy to pay you something, I didn’t see a donate button so let me know, I’m desperate!!! Ahhhhhhhhh.
I’ve gone over this and over this and tried many different little things to no avail.
PLEASE, with sugar on top, advise me.
Okay, I put the code in a file you may view at http://www.amerikabbs.com/code.html, I hope this works for you and please let me know
Thanks on thnaks
Boo
I have the form working on a hidden page on my site but when the email comes to my inbox it includes the recaptcha challenge field and recaptcha response field. Is there any way to get it to not include that in the email it sends?
Thanks, it´s really a good tutorial.
I search in other`s web sites, but they only consfused my.
I have a form.php page which is processed by a thanks.php page. I see the reCaptcha show up on the forms page, but when I click the Submit button, instead of displaying the thanks.php page, I get an error message “Premature end of script header”. I am a rank amateur, and I do not know where the error is. I checked the syntax of the thanks.php file and it is OK. The control panel for my account on the host server gives “Shared IP Address”, which is what i put in place of REMOTE_ADDR in the recaptcha_check_answer function. The rest of the thanks.php page is supposed to send an email to me with the form values and isplay a response page on the user’s browser. It worked OK before I added the reCaptcha php code. What did I do wrong?
EURIKA, I GOT IT!!! Turns out that my code was out of order, I had it all right! All I had to do was include all the PHP code in one set of opening and closing commands and move the die command to the very bottom and voila we’re in business! Al the mail works perfect now thanks to the team at 1and1 who found it in about an hour.
Thanks for you help and like I said, your work is commendable and if you send me the info I’ll get something off to you, you deserve it. I don’t have allot but I’ll get you something.
Thanks, Boo
So sorry guys, I’m completely swamped and don’t have time to help you out with this stuff right now
Now that’s completely understandable. … Does the term “…above and beyond the call of duty. …” ring a bell? Don’t even sweat the small stuff I am sure nobody here minds waiting, but can we thank you anyway?
Good job!
Thanks!
Boo
Thanks for the help. Your directions were very easy to follow and recaptcha is working great. I was wondering if it is possible (using php) to have an incorrect input return to the form with a short message to try again rather than the page with regrets and directions to return to the form.
Hi can any1 help me w.this cant seem to be able to enter php text on our web
Thank you for the tutorial. My question is regarding stripping the formating. Using the script provided, i was able to get the “clean” look, but it unfortunately, gave some of the content on my page the “clean” look too. I assume the script blocks some of the css maybe related to tags. Any ideas?
captcha fails everytime – and blog comments – questions – dont have Answers ?
what will we do now ? Not enough documentation on the official site too.
waiting for mor tutorials for those who dont have enough php knowledge.
Hi -
This was such a great resource. I have a follow-up question that hopefully hasn’t already been asked, but may be helpful to others.
In the process form, if the challenge is incorrect, text is displayed and the user must hit the BACK button to try again.
My form opens in a popup, so the user has to go to the History menu and choose “Back”.
If they close the window, they click the link to the form again and have to start from scratch.
____
if (!$resp->is_valid) {
die (“The challenge words weren’t entered correctly. Please go to your History or View menu and choose ‘BACK’ to try it again.”);
}
____
Do you know how to code in a link into the php? I’ve searched online and haven’t come up with an understandable solution.
This is what I’d hope to acheive (excuse the bad code, just used to clarify):
____
if (!$resp->is_valid) {
die (“The challenge words weren’t entered correctly. Please click here (link) to try it again.”);
}
____
Thanks in advance!!
Thank you for your time and work in producing the tutorial.
I thought it was easy to follow, however, I may be missing something as when I open my form page (contact.php) I am redirected straight to the blank recaptcha page with your error message:
“The reCAPTCHA wasn’t entered correctly. Go back and try it again.(reCAPTCHA said: incorrect-captcha-sol)”
I am not able to display or access the form page at all!
When I remove the php processing code from the file, I can display to form and recaptcha image.
I am having the exact same issue. Did you ever get a solution/reply back?
thanks
Claudia
can someone help me with a simple issue – when someone submits an email through the contact form everything works except the reply email address is blank and doesn’t use the email field that the person filled in – so when I try to reply to the emails I physically need to paste their email address in the to field – here is a sample of my code:
$to = “gabenowak@gmail.com”;
$to2 = “contact from $email”;
$subject = “this is to2″;
$date = date (“M d, Y”);
$body =
any help would be great.
@gabe you need to set that in the mail header:
$header = “From: $email”;
mail($to, $subject, $message, $header);
thanks you
sicak videolar izle
Thanks for this, this is just what I was looking for! It’s also pretty sweet to meet another woman in the field. (: Keep up the great work!
thank you for your help – I’m developing a site for a friend so it shouldn’t be on this address for long – but thanks again.
Hello, Thanks for the great script and documentation.
I have ONE problem though. I am using the re-captcha in a registration form. BOTH the processing and error messages are handled with this ONE php file (register.php). Where do i put the processor code?
I have tried putting it in the begginning of the (register.php)file, but get an error message saying the code is wrong before the form is even displayed.
I have seen a few other comments asking this specific question as well. Any help you can offer would be GREATLY APPRECIATED!
Here is my register.php file:
Registered
Thank you, you have registered – you may now Login.
<form action=”" method=”post”>
Username:
Password:
Confirm Password:
Email Address:
Image Verification
Please give me a little guidance on where the process code should go. Thanks a million!! – Mike
PLEASE READ!——————
If you are having problems getting re-captcha to work and you are using a SINGLE form to control both the form and processing (i.e. Registration form) here is your solution:
You should place the processing code right before your php commands to add the new user to the database. The processing code does NOT have to be at the very beginning of your php file as this tutorial strongly implies. And it will not work if it is.
If you have been having these problems and dont understand the solution i just posted, feel free to email me and i’ll send you code samples, etc.
Sorry, didnt know the email address wasnt shown on the posts. my email address is:
michaelnaeseth@yahoo.com
Has anyone tried the Audio function on the re-captcha? It is very BAD and needs to be fixed. Go ahead give it a try. They play a sound clip and ask you to enter the words you hear. Most of the sound clips i heard were from 50/60’s movies, there was all kinds of background noise and there were 2 people talking at the same time. WHAT A JOKE! The audible feature really needs a MAJOR overhaul.
Guess you cant ask for a whole lot from a free script. The text feature works great though.
@Mike Actually, I think it’s supposed to have bad background noise so that speech recognition bots won’t be able to crack the audio captcha.
Thanks for your reply.. Why dont you give it a try just for fun?? =) its pretty tough, I havent been able to get it once. Maybe i just got 5 of the really hard ones in a row? =P
Anyway, im just happy i figured out how to get the thing working on my registration form. I think you should include that part in your tutorial. for people who want to do the form and processing on a single form. where to stick the processing code, etc.
Hope im not offending you in anyway and i do appreciate your advice here. And if that is you in the profile pic you are as beautiful as you are smart.
Hi Inko9nito!
Congratulations for this great post! Very very helpfull!!
I’ve it implemented in my site, but I have one last question.
Here is my “sendmail.php” code (line 9) :
if(!$resp->is_valid) {
header(“location:error.html”);
die();
}
else if($resp->is_valid) {
$email = $_REQUEST['email'] ;
$message = $_REQUEST['message'] ;
$message = utf8_decode($message); //special characters
mail( “xxx@xxx.com”, “XXX”,$message, “From: $email” );
header(“location:thankyou.html”);
}
With this code running like this, do I still have to use some function against email injection or I am already safe against spambots ?
Thewizzard teachs something here but I can’t implement:
if ( ereg( “[\r\n]“, $name ) || ereg( “[\r\n]“, $email ) ) {
[... direct user to an error page and quit ...]
}
If it is needed, could you help me please?
I also read something about spambots attacking the SUBMIT button and rewriting the form inputs? With ReCaptcha they can do it too?
And just one more thing I want to share!hehehe!
Maybe I’ve found another way to costumize the look of ReCaptcha here at Lastfm Radio.
Thanks again for this great post and byebye!
Hello,
Thanks so much for your helpful instructions on how to install and use captcha. I have followed all of your instructions but my captcha doesn’t error when an invalid entry is made. I’m not sure what I’ve done wrong the captcha appears on the contact page and I am able to enter the characters but once I hit submit the validation doesn’t seem to work. Can you please help? I have added the php information to my emailform.php and uploaded the recaptchalib.php to the same directory on my server as my forms. So, I’m a little confused now as to what to do.
Any help would be greatly appreciated.
Cheers,
Cynthia.
Just an update to my first post the captcha kinda works, the problem is when the captcha is typed in and extra characters are entered to the end for some reason it will pass and send the email. Does anyone know how to fix this.
example: mailmur susp (captcha generated)
User input: mailmur susp12345
Thanks!
I have a website and im using reCAPTCHA on it, but ive had an extremely hard time getting it setup and working because i dont know PHP, well i’ve started using it, and with the help of this tutorial here i FINALLY got it working! Thank you!!
Well the problem now is you can use $_REQUEST to bring over the values of text boxes, but what about a list/menu? Putting in the name of those fields dont carry over, i have a list with all the states in it so they can pick their state, but it doesnt carry over and send to me in an email, how do you get those values?
Hi Mike,
I use list items and my email.php works so I’ve included it below if you would like to try it.
Cheers,
Cynthia.
<?php
//This is a very simple PHP script that outputs the name of each bit of information (that corresponds to the
nameattribute for that field) along with the value that was sent with it right in the browser window, and then sends it all to an email address (once you’ve added it to the script).if (empty($_POST)) {
print “No data was submitted.”;
print “”;
exit();
}
//Creates function that removes magic escaping, if it’s been applied, from values and then removes extra newlines and returns to foil spammers. Thanks Larry Ullman!
function clear_user_input($value) {
if (get_magic_quotes_gpc()) $value=stripslashes
($value);
$value= str_replace( “\n”, ”, trim($value));
$value= str_replace( “\r”, ”, $value);
return $value;
}
if ($_POST['comments'] == ‘Please share any comments you have here’) $_POST['comments'] = ”;
//Create body of message by cleaning each field and then appending each name and value to it
$body =”Here is the data that was submitted:\n”;
foreach ($_POST as $key => $value) {
$key = clear_user_input($key);
$value = clear_user_input($value);
if ($key==’extras’) {
if (is_array($_POST['extras']) ){
$body .= “$key: “;
$counter =1;
foreach ($_POST['extras'] as $value) {
//Add comma and space until last element
if (sizeof($_POST['extras']) == $counter) {
$body .= “$value\n”;
break;}
else {
$body .= “$value, “;
$counter += 1;
}
}
} else {
$body .= “$key: $value\n”;
}
} else {
$body .= “$key: $value\n”;
}
}
extract($_POST);
//removes newlines and returns from $email and $name so they can’t smuggle extra email addresses for spammers
$email = clear_user_input($email);
$name = clear_user_input($name);
//Create header that puts email in From box along with name in parentheses and sends bcc to alternate address
$from=’From: ‘. $email . “(” . $name . “)” . “\r\n” . ‘Bcc: ‘ . “\r\n”;
//Creates intelligible subject line that also shows me where it came from
$subject = ‘Subject Line’;
//Sends mail to me, with elements created above
mail (‘your email address here’, $subject, $body, $from);
?>
Just to say, thanks very much for this very helpful information. I’ve successfully installed reCaptcha on one site; five to go.
i put the captcha on my order form but when i fillin wrong words in the captcha its going further with the order process so it seems not to work properly. what do i need to change
I had posted previously but the ensuing reply said too busy at that time. Would it be possible now to re-check my problem and hopefully offer a solution? Or, maybe look more closely and assist somehow? Thanks.
Thank you so much for this tutorial! I think reCAPTCHA is a great widget, but I just couldn’t make any sense of the instructions – whereas this how-to really made it so simple that even a non-techie like myself managed. Ta muchly!
I’ve tried the code for my (to-be) website and it didn’t seem to work at first at all. Checking both the code as well as the HTML output , I couldn’t find anything wrong with it. But when I added a check to see the 2 fields (recaptcha_challenge_field and recaptcha_response_field) they appeared to e completely empty.
Since I’m using Opera as main broser, I figured to test the code under IE. There the code was processed normally, and the both fields had values.
I also found some other thing about reCAPTCHA and Opera for PhBB when googling the problem.
My question is if the java script that’s implemented is actually compatible with Opera…
can u make it for me? i cant understand after the “”zip”" something..please…help me..please…tnx…good luck
wat will i do if i put captcah in my testimonial in my friendster??? nid help
Hi there Inko9nito
Thank you very much for this post.
The short blurb at the reCAPTCHA site certainly isn’t non-coder-friendly, unfortunately.
So it’s not only nice of you to write this useful tutorial, but to then help out with folks who are having a problem.
Rock on!
TheNightOwl
P.S. I’m one of those folks who is getting an error message regardless of whether I input the right or wrong answer, but I think it might be a conflict issue. That is, on the process.php file, there is already a php-include ahead of everything, which is grabbing data from the previous page and doing various things with it.
It’s all a little beyond me so I’ve referred it to the vendor of the script I’m running.
Anyway, the point of my comment was to say “Thank you!” and to make sure you realise that you’ve helped a LOT of people with this post.
:O!!
muchas gracias, te pasaste.
está clarito.
me funcionó inediatamente
@Cynthia
Your reCAPTCHA is working exactly as designed despite the second word not matching. That’s the whole point of reCAPTCHA – it sends two words, the first it knows and the second it doesn’t. As long as the user gets the first word right then it passes, the results of the second word are collated from multiple resondants and used to translate the scanned word that could not be recognised by OCR.
@All
For those that are using reCAPTCHA as a contact/feedback form you may be interested in including the reCAPTCHA variables in the delivered messages. For example, where your scripts includes such variables as $from, $subject and $message you can also include $_SERVER["REMOTE_ADDR"] to give the connecting IP address, $_POST["recaptcha_challenge_field"] to give the unique challenger reference (if the resulting string is prefixed by http://api.recaptcha.net/image?c= then you can see the exact image (or audio file) they saw (heard), and $_POST[“recaptcha_response_field” which will give you the user’s response.
These additional variables can be useful in case you still get the occasional spam as they might give you an idea whether they are automated or not (the former really working only on simpler challenges, for which reCAPTCHA can sometimes give).
Mathew
@Mathew thank you so much for doing this. I just don’t have the time anymore.
The problem is that only with IE, reCAPTCHA passes the fields $_POST['recaptcha_challenge_field'] and $_POST['recaptcha_response_field'] on in the form. When using Opera or FireFox, both fields are NULL…
Also, when I use reCAPTCHA from my main page (registration form and contact form), it doesn’t pass the fields. But when I use it from an other part of my site (posting a comment on a user Blog as annonymous), it works perfectly fine…
Thanks Mathew for answering my question regarding the second word not matching in reCaptha validation your response really clarifies how the program works for me. I’m a new user of reCaptcha and did not fully understand how it was designed. Very helpful post!
Cheers,
Cynthia.
I’m using the reCAPTCHA on my contact form, and it’s working fine. Thank you!
I just have one problem. Before I added it, I only had the two pages (form and process), and I was able to say, “Thank you ! Your form has been submitted…”
Now that I am redirecting them to other pages, the echo command does not work (obviously–the form posted to the process page, not the redirected pages).
Can I somehow forward this data or post it to multiple pages? Let me know if you have any ideas! If not, I’ll just have to leave it off. Thanks!
You can pass a variable to those pages in the URL, specifying that the user passed the reCAPTCHA and that a thank-you message needs to be displayed. Here’s a quick how-to: http://www.scottklarr.com/topic/91/passing-variable-values-in-the-url-with-php/
Hi, got the recaptcha, but it will let members log in even if they don’t enter the correct words. If one of the words is entered with one letter wrong, it still logs in. Can you help?
reCAPTCHA only checks one word.
Ok. But it still logs the member in even if both words are incorrectly spelled?
Oh, well I was replying to the “if one word is entered with one letter wrong” part. I’m sorry I don’t really have the time to go through your code and find the problem. People above have had this problem and some of them solved it. My best suggestion would be to either go through those commens.
Hi Vera,
Thank you for this great post. I tried using the following code that you posted on 1/31/08:
if(!$resp->is_valid){
header(“location:captcha_error.shtml”);
die();
}
else if($resp->is_valid){
header(“location:form_submitted.shtml”);
}
I tried to validate (send form) the captcha several times, but each time my process.php form sends me to the captcha_error.shtml page (instead of the form_submitted.shtml page). I’m new to programming, so I’m not sure about the correct syntax for php.
In your code, I noticed that you use “$resp->is_valid” in both the “if” and “else if” statements. The only difference is the added “!” on the “if(!$resp->is_valid)” statement (and the “die(); statement). Is that correct?
Thank you in advance for this great tutorial and your help.
Genji
Hi Genji
I had the same issue as you…I’ve managed to solve it by replacing “if(!resp->is_valid)” with “if(resp->error)…the ‘!’ means ‘not equal to’ so instead of using the logic, the response is not equal to valid, I’ve made the logic, if the repsonse is equal to error.
I don’t know if there is a reason this wasn’t done in the first place, but it works for me…hope this helps.
Rob
Thanks for the easy to follow instructions.
I have followed your instructions which seem to have helped a lot of people but I can’t get the form to read the recaptcha code. The form loads without the recaptcha and ignores it when I submit. Could you tell me what I’m doing wrong?
When I click submit, I get this:
For security reasons, you must pass the remote ip to reCAPTCHA
How do I get my remote IP?
Can I pay you to fix my two pages so this works?
Hi,
I am trying to implement Recaptcha and everything is working fine expect email.
Here is the code, please help.
is_valid) {
?>
window.location.href=’http://www.softwarebpo.com/tryagain.html’;
window.location.href=’http://www.softwarebpo.com/thankyou.html’;
Regards
Srivatsan
Does anyone here have the technical knowledge of how to walk someone through installing this to someone like myself that doesn’t know a thing about php? I keep getting the arab forum posts on my website from some spammer and this seems to be the only thing that can stop it and I need help. I have msn or whatever messenging program you use I could install. Thanks.
I can not for the life of me get the Captcha image to show on my website
Don’t know what I’m doing wrong, but I can’t get Captcha to work properly. I’ve never used php before.
2 questions:
1. Can I have two forms on the same page, each with its own Captcha?
2. Do I have to have two files, one with the form and one with where to send it or can it all be done in one file?
I’d appreciate it if you could take a look at my php page and help me get it working – http://www.wellingtont2905.co.uk/response page.php
Thanks
Oops! That page should be http://www.wellingtont2905.co.uk/response%20page.php
I don’t understand this. That page does not contain all the code I am uploading to my server and only seems to include the error message. Now I’m really confused.
Here is my html page – http://www.wellingtont2905.co.uk/response%20page.html
How do I add the reCaptcha to this after saving it as a php file?
I got the image verification box to appear but when I click submit I get this whether or not I have the correct text entered in the box:
Warning: require_once(recaptchalib.php) [function.require-once]: failed to open stream: No such file or directory in /home/macxpres/public_html/help/files/mailer.php on line 2
Fatal error: require_once() [function.require]: Failed opening required ‘recaptchalib.php’ (include_path=’.:/usr/lib/php:/usr/local/lib/php’) in /home/macxpres/public_html/help/files/mailer.php on line 2
I think this recaptcha thing is a load of crap! Everyone is having trouble and I have tried to contact recaptcha through their support email and they have not even read it.
I’m finding another way to accomplish the same goal. If anyone comes up with a solid way, contact me at mike@watsonbci.com and I will do the same for you.
When I first entered the code as you specified in your instructions, I was getting error code when I tried to submit the form. It took me a little while to figure out that it was because I did not have the code on the “form.php” file inside the html tags.
Your instructions state,
“Where and How?
Put this piece of code before the Submit button, where you want the CAPTCHA to appear. It needs to be enclosed in PHP tags because…well, it’s PHP.”
You do say that the code should go before the submit button, which would normally put it within the tags. However, some people might need a more clear instruction where the code goes.
BTW, I very much appreciate what you are doing here. People can be a bit rude because they are frustrated. But, don’t take it personally.
Thanks!
In my previous post, I was trying to specify the “” html tags, but they were not displayed in the post. I have put quotations around them here and I hope they display.
Well, that did not work either. Let me try this – I am trying to specify the <><> html tags in my original post.
Well, final try – I am trying to specify the form /form html tags. (I could not put the symbols around them because they would not display properly.)
So, the bottom line is that the code for “form.php” needs to go before the /form (with around it) html tag.
Hello, My form action is: <form action="” I do not understand where to place the server side code below.
is_valid) {
die (“The reCAPTCHA wasn’t entered correctly. Go back and try it again.” .
“(reCAPTCHA said: ” . $resp->error . “)”);
}
?>
Any suggestions? Thanks as I am going insane!
From my above post the form action should read.
<form action="”
<form action="php echo $editFormAction;" Ok, with <?
hi,
i got just the one php file that has the form and the process all in one – how do i integrate your code?
i’m a afraid i might mess up everything else…
thanks.
arif.
hi,
i got just the one php file that has the form and the process all in one – how do i integrate your code?
** it’s a login form **
will also incorporate this in a email form.
i’m a afraid i might mess up everything else…
thanks.
arif.
******* ONE PROBLEM SOLVED **** 1 requires help!
After you have done everything right – the captcha will still not work. BECAUSE the keys relate to your actual website name ie. website.tld that you typed when setting up your account – but like me most probably you are testing on your localhost apache server. Hence you get an ivalid private key error.
You must offcourse also make sure your library is unzipped and placed in the correct directory.
well at least thats what i think – the experts can tell you more..
** MUST ** From the experts i would like to know about port=80. what if the isp blocks it, what port do we use, and where exactly do we make the changes in the recaptchalib.php ?
a.k.
Hi Vera, I’ve been reading and trying to get smart, but find I need advice… I’ve got the captcha box to appear on the form and it’s looks beautiful, but at this point it’s just another beautiful HTML image since I can’t get the form.php functioning correctly.
I’ve got your code in the beginning of my form.php and very carefully placed the private key. When I refresh my page I get the following message:
The reCAPTCHA wasn’t entered correctly. Go back and try it again.(reCAPTCHA said: incorrect-captcha-sol). This error has siezed focus of my page.
The only way to get the page back is to delete the code from form.php. Then it’s restored to a beautiful piece of HTML code with no Captcha functionality.
Your advice is greatly appreciated.. I’m building this site pro bono for a non profit and the lady is getting inundated with spambots from her online dog rescue application… Thanks so much.
Ursa
Oh yea,, one more thing.. don’t forget that everytime you do a new publish of your form you will need to redo the server side code. I have a Testform template of the code just in case I’m feeling doltish and forget the key strokes. Have a nice day!
Thank you for making the implementation of reCAPTCHA so much easier. I am having one problem though.
I am using the exact same set-up you demonstrate in this tutorial, where I have a front end page that the form is on with a php extension and a form action value that points to the mail handler file also with a php extension. I used the snippet of code in this tutorial in my mail handler php file. That works great now.
I also took your advice in directing incorrect code entries to a custom error page. This is where my problem starts though. When a user enters the wrong code it will send them to my error page with a back button to the form they were working on. When they go back to the form all the work they did on the form disappears, forcing them to re-enter everything.
Is there something else I can do to make it so the users don’t need to re-enter there work, just re-enter a new code and submit the form again?
I was kinda thinking an error message that would display on the form page itself instead of directing the user to a different page. I just don’t know how to do that.
Thanks,
-Austin-
Make the error message a popup instead of new page….
Hi -
I have the Captcha coming up correctly in my form…then when the user submits the form and is forwarded to the form processing page (where i insert into a DB if the challenge is OK) – i notice that these fields are not returning any values:
$_POST['recaptcha_challenge_field'],
$_POST['recaptcha_response_field']
When I view my form source – this is what it shows:
;
I am doing this in Firefox.
Thanks for the help,
Does anyone know how to re-size the recaptcha? It’s too large for the space I need it in.
http://www.pemc.com/firsttimebuyer
Thanks,
Kristan
i don’t understand completely; do you have to fill the privatekey and publickey in in the “…” that’s at the start, OR do you have to replace privatekey with the actual private key, and publickey with the actual public key? :\ when i try the first option my reg. form works but it doesn’t show the recaptcha AND when i try to register it errors and says that a new code has been generated (which is kinda hard for people to find if it doesn’t show the actual recaptcha XD), and when i try the second option i only get errors on the lines i’ve exchanged the publickey and privatekey with the actual keys. ; _;
Brilliant, your help got me all installed in less than 5 mins. Thanks
@Mewis your actual private key string goes inside the quotes instead of the ellipsis (…)
Hi Vera, just a big ‘thank you’ for making it so easy for me to add Captcha to my very first php form – good luck with whatever ventures you embark on… oh, btw I love the URL name!
Graeme
I use Dreamweaver 8 and I built a form inside an .html page and it then processes through a .php form.
So, I tried all your instructions and I couldn’t get it to work?
I assume my problem is that my form is in an .html page; which I did change the extension to .php. Still no luck..
Any suggestions?
S
Never mind my last post, I figured it out. THANKS!!!!
I do have one question still. In the actual form that comes to my e-mail address I get this “Recaptcha challenge field: (plus a lot of letters in the actual form)”
Is there anyway to prevent this from showing up in the actual form that comes to my e-mail?
Cheers,
S
Hi, thanks for a great tutorial.
I had a problem where I kept getting the message:
The reCAPTCHA wasn’t entered correctly even though I had entered it properly.
Turns out my form didn’t have the method=”post” in it.
Hope that helps others.
@inko9nito
Great tutorial and thanks for clarifying for the Recaptcha people.
However, I’m having the same issues as a previous post — Genji – 05.13.09 at 7:09 pm
The issue is when replacing the plain error message with the option of my own page that changes its response according to whether it is a ‘pass’ or ‘fail’ it always returns ‘fail’.
Please can you tell me where I (or it) is going wrong?
Thanks
Rob
@inko9nito
First of all thanks for your time… This is my second job and first with form!
Three PHP files were created:
1. traveler-form.php
2. travel-club-process.php
3. travel-registration-completed.php
The form page ( http://rent-a-week.com/traveler-form.php ) perfectly and the process page send it to the completed page. From the surface everything works perfectly. But not email…
Then I learned about…
and placed it in the process page below the recaptcha code, like this…
is_valid) {
die (“The reCAPTCHA wasn’t entered correctly. Go back and try it again.” .
“(reCAPTCHA said: ” . $resp->error . “)”);
}
?>
and not even a blank email to the assigned address arrives.
Yes, I suspect that the variables must match the form’s ID’s to get the info users plugged in, but at least an email should’ve been triggered. (?!?!?!?).
Questions:
1. Where do I place the above code? a) Form page; b) process page; or c) registration completed page.
2. Once I know on which page, where within THAT page it should be inserted?
3. Any suggestions?
Thanks so much in advance!
Victor
The above post got cut off… Too long perhaps!
It should read:
Then I learned about…
and placed it in the process page below the recaptcha code, like this…
is_valid) {
die (“The reCAPTCHA wasn’t entered correctly. Go back and try it again.” .
“(reCAPTCHA said: ” . $resp->error . “)”);
}
?>
and not even…. Everything came out from this point.
Victor,
Did you use the script to format the verification. I was trying to remove the color scheme. I noted that the size increases when I use the script for a “clean” format.
Great post – i followed your instructions and everything worked without a hitch!
Trying to use this clip for a formmail.pl (perl plug-in). Not sure what script to place inside the formmail.pl script which is the process form for my contact.php.
Trying to use this script with (cgi/formmail.pl) as the form process script. Not sure of the process after reading installing reCaptcha using .php scripts.
Can you provide the instructions for installing reCaptcha using cgi/formmail.pl?
I followed the instructions from your blog as best I could, and the reCaptcha shows up on my contact page. However, when I submit the form, I get two error messages:
Warning: require_once(/recaptchalib.php) [function.require-once]: failed to open stream: No such file or directory in /home/content/s/q/r/sqrgroup/html/webformmailer.php on line 3
Fatal error: require_once() [function.require]: Failed opening required ‘/recaptchalib.php’ (include_path=’.:/usr/local/php5/lib/php’) in /home/content/s/q/r/sqrgroup/html/webformmailer.php on line 3
What do I need to do to fix these?
Thanks in advance for your help.
Ok. Now that’s fixed, but I’m getting a Page Not Found message after I click Submit. Any ideas?
Thanks
OK, I got the advance results going on and it doesnt seem to be working when the Captcha Passes. It goes to the page, but does not display the $content – However when I post use the form and fail the captcha, the $content is shown on the page. The form is working perfectly otherwise. Just not showing the Pass $content when it passes the Captcha Script.
Here is what I look like in my code.
On the page, thankyou.php
On the page, email.php
if (!$resp->is_valid) {
header(“location:thankyou.php?result=fail”);
die();
}
else if ($resp->is_valid) {
header(“location:thankyou.php?result=pass”);
}
Well it took and hide the tags and everything between, this is the page code without the (spaced on purpose)
OK, I got the advance results going on and it doesnt seem to be working when the Captcha Passes. It goes to the page, but does not display the $content – However when I post use the form and fail the captcha, the $content is shown on the page. The form is working perfectly otherwise. Just not showing the Pass $content when it passes the Captcha Script.
thankyou.php page has,
if (isset($_GET['result']))
{
$result = $_GET['result'];
}
if ($result == “fail” )
{
$content = “The CAPTCHA code was entered incorrectly. Please go back to enter the code and send your form.”;
}
if ($result == “pass” )
{
$content = “Thank you for your inquiry. Someone will contact you soon. Most times within 48 hours.”;
}
echo $content;
The email.php script page has,
if (!$resp->is_valid) {
header(”location:thankyou.php?result=fail”);
die();
}
else if ($resp->is_valid) {
header(”location:thankyou.php?result=pass”);
}
@Sabrina
It sounds like your code is missing the page or the page does not exsist in the form..
Code for the form for a “Thank You” page will look like,
if($send)
{header( “Location: http://www.website.net/thankyou.php” );}
You have to make sure you create a thankyou.php page
Hi,
I’m just after some code so when the user types in all their info and don’t get the captcha right, that when they go back to the form page they don’t have to type in their info again.
Also can the captcha verify without going to the process page so a instant msg is displayed when the send button is pressed stating that the code is wrong?
custimizing ReCaptcha and thus getting rid of the buttons, more here:
http://recaptcha.net/apidocs/captcha/client.html “Look & Feel Customization”
HELP! Every time I try and implement the captcha all i get returned is a message saying the captcha was entered incorrectly even when it wasnt. I have checked and rechecked my public and private keys, however i cant find any other fault with the code! The code is as follows
if($form==”comment”)
{
?>
Name:
Dates of Stay (dd/mm/yyyy): to
Comment:
is_valid)
{
die (“The reCAPTCHA wasn’t entered correctly. Go back and try it again.” .
“(reCAPTCHA said: ” . $resp->error . “)”);
}
else if ($resp->is_valid)
{
$name=$_POST[name];
$start=$_POST[start];
$end=$_POST[end];
$comment=$_POST[comment];
mysql_selectdb(‘hausande_apartment’, $con);
$sql = “INSERT INTO guestbook (1, 2, 3, 4)
VALUES(‘$1′, ‘$2′, ‘$3′, ‘$4′)”;
if(mysql_query($sql, $con))
{
echo “Entry submitted, click here to go back to the guestbook”;
}
else
{
echo “error: ” . mysql_error();
}
}
}
?>
The code in my previous post did not display correctly so here it is in a text file http://www.haus-anderl.com/apt.txt
Hi, I am having some trouble where reCaptcha will not recognize the value I entered. I keep getting this error message:
The reCAPTCHA wasn’t entered correctly. Go back and try it again.(reCAPTCHA said: incorrect-captcha-sol)
I did some testing and I do not see how the variables are passed into the second program.
“recaptcha_challenge_field”
“recaptcha_response_field”
What am I missing.
Also. my process pgm is posting to mySQL if that makes a difference.
Thanks,
Glenn
I have recently created the form (contact_form.php), process(contact_process.php) php files and edited the recaptcha.php to include the public and private code. I created a simple thankyou.htm file to determine whether anything worked.
First do I need to upload my website to my host server to view the CAPTCHA? I don’t know if that’s necessary. If it isn’t then my CAPTCHA does not appear and I am stuck. If it is required, then let me know.
Second, I want the results of my data in my form to be sent to my email located (I think) in the contact_process.php.
Third, here is the code for the form:
Name:
Phone Number:
Email:
Message:
Fourth, here is the contact_process.php:
is_valid) {
die (“The reCAPTCHA wasn’t entered correctly. Go back and try it again.” .
“(reCAPTCHA said: ” . $resp->error . “)”);
}
$Contact_Name = $_REQUEST['Contact_Name']
$Contact_Phone_Number = $_REQUEST['Contact_Phone_Number']
$email = $_REQUEST['email'] ;
$message = $_REQUEST['message'] ;
mail( “max_rittner@mysite.com”, “Feedback Form Results”, $Contact_Name, $Contact_Phone_Number, $message, “From: $email” );
header( “Location: thankyou.htm” );
?>
Fifth, I have included the Mailhide API code to include it in the recaptcha.php file:
/* gets the reCAPTCHA Mailhide url for a given email, public key and private key */
function recaptcha_mailhide_url($pubkey, $privkey, $email) {
if ($pubkey == ‘01WE3U0Vw6iRA5GqdIEltMGg==’ || $pubkey == null || $privkey == “FE50D88D43FCAFB61D79A033A4FAA2DF” || $privkey == null) {
die (“To use reCAPTCHA Mailhide, you have to sign up for a public and private key, ” .
“you can do so at http://mailhide.recaptcha.net/apikey“);
}
Finally, I have tried to follow your instructions, but I have had no success, so far. Could you check to see if my code is correct? If it is just a matter of uploading my site to my host serever, then I will be relieved to hear it. Thanks.
PS. I even tried to see the reCAPTCHA Hello World file. No luck.
I’ve got my RECAPTCHA working, but now I am getting the following error:
Parse error: syntax error, unexpected T_VARIABLE in D:\Hosting\4474015\html\contact_process.php on line 15
Help!
Everything seems to be working, however after seeing the thankyou.htm page I assume that an email was sent to my site. So far, nothing has arrived, either in my Junk Mail or ortherwise. Am I missing something in the contact_process file?
Now it is all working. The field names in my form need to be restricted to lowercase and possibly a specific length. Right now, I am not concerned about size, not size doesn’t matter.
One final concern, if I have four fields in my form then how do I code it so that the data in all 4 fields get sent in onee email instead of separate emails?
mail (“max_rittner@bizedlogic.com”, “Feedback Form-Contact Name”,$name, “From: $email” );
mail (“max_rittner@bizedlogic.com”, “Feedback Form Results-Contact Phone Number”,$phone, “From: $email” );
mail(“max_rittner@bizedlogic.com”, “Feedback Form Results-message”,$message, “From: $email” );
hi
just one question ?
How do i keep the field write’s when there are errors in recaptcha ?
thx
az’
I installed everything for the recaptcha code on the site. It works fine with Google Chrome and Firefox, but for some reason I can’t get it to show up on internet explorer. Do you think you could give me a hand?
Hi,
Thank you Very much! It was really helpful. I am using recaptcha on my contact form. Its more secure now!
Great stuff!!! Thanks once again!!!
Hi – thank you so much for writing this! I am just learning PHP and this worked flawlessly with my form. You made it really easy to customize the error page too…thanks!!
I love the post but apparently REALLY don’t know enough about HTML and the web as I cannot get reCaptcha to work for a non-profit site I maintain. I’ve spent hours trying to figure out why the script won’t display. Fixed that. Now no matter what is typed in the check box, the form is submitted. Please help as I cannot for the life of me figure out why our job bank insists on posting every job sent (today alone I had 25 spam listings for porn) and even with this script all I have is an image that doesn’t block anything. The site is
http://ad2phoenix.com/jobs/job-post.php
Thank you for any tips you can offer.
Your link to ad2phoenix.com is not available… it seems so…
Hello,
Can you please let me know what I’m missing.
This is the error I get:
The reCAPTCHA wasn’t entered correctly. Go back and try it again.(reCAPTCHA said: incorrect-captcha-sol)
I don’t even get the option to enter the captcha code, this is the message that takes over my form.
thank you
Claudia
Thank you very much! This works great!
My client is looking for CAPTCHA for their site so I decided to test it out on my company website.
I could not get the code to work that allows the error message to open in a new page (I did change the location: to the new page) – it opened up my mailer.php page (which is the php page that submits my forms) and made it show up completely blank.
Removed that, got it to work and send emails, however my website’s formatting was messed up (both on my contact.php page and mailer.php page – both in different ways) when viewed/filled out with Explorer 7 and Mozilla 2 (on PC) – but it worked fine in Mozilla 3 on Mac. I ended up removing it, since it wouldn’t work well in IE 7 on PC (which a lot of people still use). Perhaps it’s me, or the way I designed my site, but my site now looks fine without the CAPTCHA scripts in these same browsers.
It’s a shame too, as I was really looking forward to using it. If anyone has any solutions to my issues, please let me know!
Thank you for this great blog post – a lot easier than the instructions on the reCAPTCHA website.
What a great post. Very easy to follow and implemented the reCAPTCHA simply with your instructions. However, I can get it to work on IE, but I get the following message on Firefox and Safari.
“The reCAPTCHA wasn’t entered correctly. Go back and try it again.(reCAPTCHA said: incorrect-captcha-sol)”
I sent the question to reCAPTCHA and posted it on their forum and haven’t had anyone be able to tell me what went wrong. I was hoping you could shed some light on this for me.
Thanks!
Jodi
I found this post on another forum and it finally solved my problem.
Thought I would share it here in case anyone else has this issue too.
I Keep Getting “incorrect-captcha-sol” When Submitting Correct Words
Don’t know exactly what caused this error, but I repeatedly got this
error even though I was entering the correct words. Using the PHP
version and testing in a Mozilla Firefox browser. I originally had the
inside a
, once I moved the form outside of the table, it worked fine. Checked
forums for a while to find this answer, figured it should go here.
Hey what if my contact page is on a .html page?
I can’t enclose php tags so is it impossible for me to add a reCAPTCHA or any kind of CAPTCHA?
I’ve got the reCaptcha working just fine. Thanks for a very useful tutorial.
Now for a different type of problem. I’d like to have two different error messages, one for the reCaptcha box, and one for the feedback form. I’m using the “two files” version.
Are you able to handle another tutorial?
I am installing captcha but I am getting the error message ‘could not open socket’ . I have installed the recaptcha file and also modified the registration.php with the above public and private keys.
For the process.php file, where does the Recaptcha code go? I put mine at the beginning as the tutorial suggests, and it does not work. Where should i put it? Also, do i need separate PHP tags around the repatcha code? I don’t think I do, because the whole process file is PHP, but just want to make sure. Thanks for your help.
is_valid) {
die (“The reCAPTCHA wasn’t entered correctly. Go back and try it again.” .
“(reCAPTCHA said: ” . $resp->error . “)”);
$myemail = “jet@embjapan.org”;
$subject = “JETAADC Member info”;
/* Check all form inputs using check_input function */
$fullname = check_input($_POST['fullname'],”Please enter your full name.”);
$jetyears = check_input($_POST['jetyears'],”Please enter the number of years on JET.”);
$pref = check_input($_POST['pref'], “Please enter your prefecture.”);
$jettype = check_input($_POST['jettype']);
$address = check_input($_POST['address'],”Please enter your mailing address.”);
$email = check_input($_POST['email'],”Please enter your email address.”);
$phone = check_input($_POST['phone']);
$title = check_input($_POST['title']);
$jobtype = check_input($_POST['jobtype']);
$where = check_input($_POST['where']);
$otherfield = check_input($_POST['otherfield']);
$otherjobrltjpn = check_input($_POST['otherjobrltjpn']);
$comments = check_input($_POST['comments'];)
Ben,
I have my reCAPTCHA code in it’s own php tags and then the next php information in it’s own tags. Mine works, so you may want to try that.
Jodi
Thanks. Do I put the reCAPTCHA code at the beginning? It doesn’t work for me.
Ben,
This is how mine is in the form.
is_valid) {
die (“The reCAPTCHA wasn’t entered correctly. Go back and try it again.” .
“(reCAPTCHA said: ” . $resp->error . “)”);
}
?>
Note: private key and process information was left out on purpose. Make sure your key is correct.
Hope this helps.
Jodi
That didn’t copy right into the form let me try it again.
Ben,
It won’t let me copy or even write the code into this post. Just put your
php tag – captcha code with the private code in it – end php tag.
php tag – process form info – end php tag.
Would you have a look at implementing captcha spam preventor, on our matt PHP form mail CGI script
Let us now at the above address
This is my error code. “The reCAPTCHA wasn’t entered correctly. Go back and try it again.(reCAPTCHA said: incorrect-captcha-sol)” What did I do wrong?
I changed the form and I now get form but I need it go to url. I am not using your form I am using Cap page to get it work.
Why your blog is not secured against the bots, If you are publishing the re-CAPTCHA you should protect against the unwanted comments on the blogs. Just a lighter side..!
Check out fancy captcha on this website
https://www.hosterware.com/contact_us.html
looks well cool
James,
Turn off your javascript and see what happens to that Captcha.
thnks for the post its a great help
though i cant seem to get this to work. i always get the “The reCAPTCHA wasn’t entered correctly. Go back and try it again.(reCAPTCHA said: incorrect-captcha-sol)”
thnks
elizabeth
Hello and really thanks for this post.
I’m “near the truth” in my configuration but I have just one last problem :
I have this error message once the message is sent (and I receive it in my mailbox) :
“Warning: Cannot modify header information – headers already sent by (output started at /mnt/107/free.fr/2/7/patoisfontcouverte/sendmail.php:14) in /mnt/107/free.fr/2/7/patoisfontcouverte/sendmail.php on line 20″
Normally, the page called “http://patoisfontcouverte.free.fr/merci.html” should open at the end of the message…but it is not
Could you help me solving this problem ?
thanks
I don’t know what I’m doing wrong,
recaptchalib.php in same folder as form file.
I entered (before anything else and before
is_valid) {
die (“The reCAPTCHA wasn’t entered correctly. Go back and try it again.” .
“(reCAPTCHA said: ” . $resp->error . “)”);
}
?>
Then entered after and before
var RecaptchaOptions = {
theme: ‘clean’
};
Then entered just before “SUBMIT” button,
<?php
require_once('recaptchalib.php');
$publickey = "correct public key"; // you got this from the signup page
echo recaptcha_get_html($publickey);
I setup file as .php Nothing works.
Can someone help fast please?
I don’t know what I’m doing wrong, (first message is not right)
recaptchalib.php in same folder as form file.
I entered (before anything else and before “html”,
?php
require_once(‘recaptchalib.php’);
$privatekey = “correct private key”;
$resp = recaptcha_check_answer ($privatekey,
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]);
if (!$resp->is_valid) {
die (“The reCAPTCHA wasn’t entered correctly. Go back and try it again.” .
“(reCAPTCHA said: ” . $resp->error . “)”);
}
?
Then entered after “head” and before “/head”
script type= “text/javascript”>
var RecaptchaOptions = {
theme: ‘clean’
};
/script
Then entered just before “SUBMIT” button,
?php
require_once(‘recaptchalib.php’);
$publickey = “correct public key”; // you got this from the signup page
echo recaptcha_get_html($publickey);
?
I setup file as .php Nothing works.
Can someone help fast please?
I had to eliminate the “” from previous message so it would show full code.
The problem with this installation is that there are so many codes floating around from so many different people that it’s almost impossble to figure this out.
At any rate, I was able to install the widget after tinkering with the code for 2 days and is now visible on the page, but CAPTCHA is not checking the answers.
It will process “submit” whether or not you copy the right words and even when the answers are left blank. I’ve checked some of the other web pages were people are claiming “success” with the installation and while the widget is visible the answers are not being processed “some success”.
Can someone who was able to do the installation and it’s working fine meaning, that the program is checking the answers, send me the URL for the web page so I can check the code? Thank you.
People, when posting your comments please include the URL so other people can check the “source code”
This code works, but won’t verify answers. By the way upload file as HTML, if you upload .php it won’t work.
is_valid ) {
} else {
die (“The reCAPTCHA wasn’t entered correctly. Go back and try it again.” .
“(reCAPTCHA said: ” . $resp->error . “)”);
$error = $response->error;
}
}
echo recaptcha_get_html( PUBLIC_KEY, $error );
?>
I hope tht this code posts correctly, sometimes it loses the brackets
half the code didn’t post above, send me an e-mail mediawebpad@aol.com
Love your blog helping people with recaptcha. I have two questions:
I have the captcha displayed on the page but I can fill out the form and the captcha does not effect it. Meaning you don’t have to fill in the image to send the form.
The other issue is when I place my code in front of the “submit” button, the button does not display
So right now I have the captcha code after the submit button (which is the reason for the first issue I mentioned)
I know that I am close to resolving some of this but thought I would reach out to you and see if you have a solution. Also wanted to tell you what a great page you had.
Many thanks.
Even when the correct words are entered, I get the message: “The reCAPTCHA wasn’t entered correctly. Go back and try it again.”
I’ve checked the public and private keys are OK, but in the process.php line:
$_SERVER["REMOTE_ADDR"],
should the REMOTE_ADDR be replaced with something?
If so, what?
Thanks
I have the code box displaying, but when the correct response is entered and the submit button is displayed, nothing happens (except a new challenge box appears). I believe I need to code the mailto address in the form tag, but doesn’t that defeat the whole purpose?
Link at: http://www.whatwouldwaltdo.com/Secure_Server/captcha%20test%203.php
I just installed recaptcha.
I follwed these steps after the download.
#1 uploaded the recaptchalib.php in the folder where my forms live.
#2 I added the following codes to this file: addentry.php
require_once(‘recaptchalib.php’);
$publickey = “…”; // you got this from the signup page
echo recaptcha_get_html($publickey);
require_once(‘recaptchalib.php’);
$privatekey = “…”;
$resp = recaptcha_check_answer ($privatekey,
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]);
if (!$resp->is_valid) {
die (“The reCAPTCHA wasn’t entered correctly. Go back and try it again.” .
“(reCAPTCHA said: ” . $resp->error . “)”);
}
Note: I added my public key and my private key as provided.
After I save the file.
This is what it gives me when “sign the guestbook” is clicked on:
“The reCAPTCHA wasn’t entered correctly. Go back and try it again.(reCAPTCHA said: incorrect-captcha-sol)”
All I did was click on the “sign the guestbook”
I am using the old version Advanced Guestbook 2.3.1
It would be nice just to upload the Advanced Guestbook 2.4.3 since it has a built-in captcha. But Yahoo, my host server, won’t allow any files with (.) at the start of any file names. So I am stuck with the old version.
Need some help.
I have followed this excellent guide to get my reCaptcha setup on my site using PHP, however the buttons (reload and audio) do not work. They simply open a new blank tab in my browser.
The buttons are linking to the following:
Reload button: javascript:Recaptcha.reload()
Listen button: javascript:Recptcha.switch_type(‘audio’)
I realise that i need some javascript in my page for these buttons to reference to, but can’t for the life of me find it.
Can anyone advise?
I have now resolved this, I had set the default hyperlink target for my page to “_blank” which was forcing the reCaptcha buttons to attempt to run in a new window.
My situation:
I am using this on a SSL page, with the correct settings. Both keys are fine and the POST data is correct. (The data makes it to the second form.)
However, the code that handles the “recaptcha_check_answer”, never replies with any type of response… not even an error. The page just hangs, waiting for something.
I attempted to bypass the check for is_valid, and ECHO the $resp object. I simply get a warning that it can not be turned into a string.
There are two things which I think might possibly have an impact on the failure to check the answer. First, the actual file is above public_html, for security reasons. Though, it generates the initial recaptcha box without issues from that location. The second possible issue is that all my pages require UTF-8 as the language/text format. This has caused issues in certain rare instances, related to CHR conversions, but the output is all alphanumeric-US.
The only error that ever came up, was the one about the is_valid, related to the class-object.
My server has “MagicQuotes OFF” for security reasons, and “Globals OFF”, also for security reasons. This is on PHP5.
I can’t think of anything-else that may be causing issues. I did have to OPEN the original file with WORD, and save as ASCII, so it could be read with NOTEPAD, to be sent to the server. (It lacks “Windows RETURN”, chr 10+13, which made it impossible to edit and copy in notepad. One long line of text gets broken in notepad as it wraps, with auto-wrap off. Only so may characters can fit onto one actual line in notepad.)
Please help.
I can link you to the test page, and mail you the actual code. However, I refuse to post it in a blog that chews-up code, and is actively indexed by google and other spiders.
Thank-you in advance, if you can find the time to help me.
Thanks for taking the time to write the instructions for implement reCAPTCHA.
its so easy and functional.
Great!
Congratulations my best wishes Success and Health
Thank you, thank you, thank you! I have tried using the instructions on recaptcha’s website and can get the captcha to appear but no matter what I input, the captcha would still pass. Not good.
Using your instructions, I was able to get the captcha to function properly and to fail if the incorrect text was input.
I am currently using Mindpalette’s Process Form script and have a formresults.php that displays what the user input into the form as a way of showing the user what they sent. Is there a way to hide the Response field on the results page? It just shows some garbled letters.
hi,
Recaptcha not workign in firefox, working well in IE 8.
any suggestions.
I had the same exact problem!
I found this post on another forum and it finally solved my problem.
Thought I would share it here in case anyone else has this issue too.
I Keep Getting “incorrect-captcha-sol” When Submitting Correct Words
Don’t know exactly what caused this error, but I repeatedly got this
error even though I was entering the correct words. Using the PHP
version and testing in a Mozilla Firefox browser. I originally had the form
inside a table, once I moved the form outside of the table, it worked fine.
Hi,
I keep getting this message whether it’s correct or incorrect challenge:
Fatal error: Call to undefined function: recaptcha_check_answer() in [my forms script]
Any ideas?
I get this error and i dont know why. I have the proper Keys. I have been up for 5 hours trying to figure out why. Can you help me? I just want it working. I copied and pasted and followed all the instructions.
I followed a tutorial on Adobe’s site a while back on how to use dreamweaver to build a single form page.
After getting spam, I tried to follow this tutorial on how to setup the recaptcha, but my problem included just having one file that displayed, had the submit form, and processed the submit as an insert into my database.
If you are in a similar situation, this might help.
Near the top of your code you should have an
if (isset($_POST[" "])) {
that has the name of your input type “hidden” from your form in the quotes, mine was MM_Insert because of how dreamweaver labled it.
This is a check to see if your insert was submitted and then the codes that follow inserts your form into your database, just before it calls the info from your database for display.
It is after this IF statement but before any of the code that follows is where you will enter your code that would go on the 2nd file of the two file method.
I also added else{ to it and hunted down the } bracket that closes the If (isset($_POST[...])) { and added the closing bracket for the else statement. This will then show the error if it was submitted but the recaptcha wasn’t proper, }else{ follow the code that originally inserts }
I hope this makes sense and helps someone that was in the same predicament.
I’ve got the reCaptcha working just fine. Thanks for a very useful tutorial. it is working mozilla and ie
This is driving me nuts, no matter what I do I get this on my webpage. I know it must be something obvious and I’m being more than a bit thick but URGHHHHH…..
Warning: require_once(recaptchalib.php) [function.require-once]: failed to open stream: No such file or directory in /home/fhlinux184/p/premierdisco.co.uk/user/htdocs/emailus.php on line 161
Fatal error: require_once() [function.require]: Failed opening required ‘recaptchalib.php’ (include_path=’.:/usr/share/pear/’) in /home/fhlinux184/p/premierdisco.co.uk/user/htdocs/emailus.php on line 161
how to use recaptcha into my website.
after integration of recaptcha i m getting the following error.
is_valid ) {
} else {
die (“The reCAPTCHA wasn’t entered correctly. Go back and try it again.” .
“(reCAPTCHA said: ” . $resp->error . “)”);
$error = $response->error;
}
}
echo recaptcha_get_html( PUBLIC_KEY, $error );
?>
I don´t know about where the error appear is when you fill the box with the letters of image ?
Or look like the Error in your Public Key number it´s wrong.
i was getting ther same error of above, the solution for me was rename the file to php, thanks for this tutorial, in recaptcha was not mentioned the need to be a php file
I’m not sure what i’m doing wrong, but the script works fine in my email form… except the fact that i can click the submit button without typing in the captcha and it still sends. i have the code before the submit button, so i don’t know wth i’m doing wrong. if you need any more information on what i’ve done, or didn’t do, just let me know.
where is reCapcha on this site?
I was wondering how to implement this if i dont call to a ‘process.php’ file…. all my scripts are internal, on the form page itself. Using DW thats how the page was constructed… I tried making the page to use external scripts and i cant get it to work.
My form action calls to “” and all my scripts are at the top of my form… anytime my page loads it gives the not entered correctly error…. help please, thank you
got cut out… my form action call to “dynamic variables, dynamic variables”