Skip to content
12.12.07 / inko9nito

Installing reCAPTCHA with PHP

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.

Advertisements

611 Comments

Leave a Comment
  1. Pud / Jan 10 2008 1:57 am

    Thanks – great post!

    • none / Mar 25 2010 6:27 pm

      The reCAPTCHA wasn’t entered correctly. Go back and try it again.(reCAPTCHA said: incorrect-captcha-sol)

      no matter what I do I get this all the time.

      Question where it says “REMOTE_ADDR” do I have to put my IP in here? or my domain url?

      • Keith N. / Mar 26 2010 3:57 pm

        No, leave REMOTE_ADDR exactly as it says in the code. You probably have something else going on.

        Are you testing with Internet Explorer? Firefox? Other? There is a Firefox bug that will always give a fail in certain conditions (search below for Firefox).

        Also, I posted a proven solution for a similar problem below. Search this page for the text “Glad to hear it Dan.” There was a serious error in the first if/then logic for the validation code.

  2. Sunny / Jan 10 2008 6:06 am

    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.

  3. inko9nito / Jan 10 2008 1:50 pm

    Unfortunately, I only know how to do this in PHP and I haven’t used ASP before 😦

  4. julia / Jan 16 2008 2:15 am

    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

  5. inko9nito / Jan 16 2008 2:24 am

    Yes, the form must have the .php extension, otherwise it won’t work. Added this note to the post itself. Hope this helps.

  6. julia / Jan 17 2008 6:39 am

    Thanks. I found another source where it works with other type of Captcha. Here is the link http://identipic.com/.

  7. heather / Jan 26 2008 3:57 pm

    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

  8. heather / Jan 28 2008 5:50 pm

    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

    • mido / Jun 12 2010 10:38 am

      hi
      i get same situation here, can you tell me how you done ?
      thanks a lot

  9. Shoaib / Jan 30 2008 11:25 am

    Love it, Thanks for making my life easier.

  10. joallen / Jan 31 2008 12:09 pm

    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)

  11. inko9nito / Jan 31 2008 4:38 pm

    You can use it anywhere really.

    Here’s how to specify a custom error page (line 9):

    if(!$resp-&gt;is_valid) {
    header(&quot;location:captcha_error.php&quot;);
    die();
    }
    

    If you want to specify a “message sent” page if captcha was entered correctly, after the code above, add this:

    else if($resp-&gt;is_valid) {
    header(&quot;location:form_submitted.php&quot;);
    }
    

    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-&gt;is_valid) {
    	header(&quot;location:form-submitted.php?result=fail&quot;);
    	die();
    }
    
    else if ($resp-&gt;is_valid) {
    	header(&quot;location:form-submitted.php?result=pass&quot;);
    }
    

    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 <a href='history.back(-1)' rel="nofollow">go back</a> 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; ?>
    
    • Philip Dahl / Jun 9 2010 7:02 am

      Very cool! thank you so much!
      I realized you were referring to the file the form is on not a new php file named “form-submitted.php” which i initially thought. After getting a blank page from the php directing the user to a pass or fail of the “form-submitted.php” I realized my mistake. I hope this saves some time for other people.

    • sercan / Feb 28 2012 9:35 pm

      I’m exhausted. I just can’t create a working form-submitted.php which will show the results in one page. Can anyone please specify every file with exact contents that should be inside? Thanks.

  12. abrogard / Feb 2 2008 6:24 am

    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

  13. inko9nito / Feb 2 2008 2:22 pm

    @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?

  14. abrogard / Feb 5 2008 6:20 am

    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 🙂

  15. Amy / Feb 5 2008 12:12 pm

    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!

  16. Jaan Kanellis / Feb 6 2008 7:50 am

    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

  17. Amy / Feb 6 2008 9:19 am

    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!

  18. Amy / Feb 6 2008 9:21 am

    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” );
    ?

  19. erwin quita / Feb 21 2008 5:25 am

    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

  20. matt / Mar 19 2008 2:14 pm

    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

  21. kit / Mar 24 2008 12:12 pm

    Thanks you just saved me about 2 hours of frustration!

  22. Hammad / Apr 1 2008 12:15 am

    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

  23. Jay / Apr 2 2008 9:39 am

    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

  24. Nate Reutter / Apr 2 2008 5:44 pm

    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.

  25. Cindy / Apr 17 2008 6:42 pm

    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.

  26. inko9nito / Apr 17 2008 8:16 pm

    @Cindy No, you can’t modify the words.

  27. stacey / Apr 28 2008 9:54 am

    Awesome! Thanks so much for the clear, easy instructions!

  28. Nicole / Jun 5 2008 10:18 am

    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.

  29. Christopher / Jun 6 2008 6:04 am

    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 . “)”);
    }
    ?>

  30. Christopher / Jun 6 2008 6:04 am

    I think something got cut off my last post…

    is_valid) {
    header(“location:captchaerror.php”);
    die();
    “(reCAPTCHA said: ” . $resp->error . “)”);
    }
    ?>

  31. Jack / Jun 29 2008 4:21 pm

    Thank you. Your instructions are much clearer than the documentation provided by reCaptcha.

  32. Liz / Jul 5 2008 11:23 am

    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.

  33. Gray / Jul 19 2008 4:42 pm

    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).

  34. Gray / Jul 20 2008 8:39 pm

    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!

  35. Saleem / Jul 22 2008 11:13 pm

    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

  36. inko9nito / Jul 23 2008 8:53 am

    @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!

  37. Andrea / Jul 25 2008 8:02 pm

    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

  38. Jeremy / Aug 11 2008 11:26 pm

    Great tutorial! After two days and many hours, your explanation did the trick. Thank you!!!

  39. Linda / Aug 26 2008 10:13 am

    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?

  40. dimitri / Aug 31 2008 6:32 am

    @ 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

  41. inko9nito / Aug 31 2008 6:44 am

    @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 😦

  42. dimitri / Sep 3 2008 12:14 pm

    @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

  43. akulavolk / Sep 5 2008 1:02 pm

    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,

  44. inko9nito / Sep 5 2008 1:58 pm

    @akulavolk Do the sample files that come with the reCaptcha PHP Library not work for you?

  45. Liz / Sep 10 2008 3:23 pm

    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!!!

  46. Cindy / Sep 13 2008 12:36 pm

    Is there any way to make the reCaptcha box smaller? Nice tutorial — thanks!

  47. Cindy / Sep 13 2008 2:00 pm

    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”);
    }
    ?>

  48. Jill / Sep 15 2008 7:43 pm

    Thank you so much for this easy explanation!

  49. LaZea / Sep 15 2008 8:49 pm

    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.

  50. inko9nito / Sep 15 2008 9:00 pm

    @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 🙂

  51. Francisco Gomez / Sep 19 2008 3:03 pm

    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.

    • Bob Shockey / Jul 29 2009 12:14 am

      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?

  52. Ginny Schweiss / Sep 29 2008 3:49 pm

    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

  53. Abhishek / Oct 5 2008 11:10 pm

    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

  54. Imokon / Oct 12 2008 5:46 am

    Wonderful refresher. Thank you.

  55. David / Oct 13 2008 9:40 am

    Good job. Your instructions really helped.

  56. Chris / Oct 17 2008 12:05 am

    excellent tutorial!

  57. Archit / Oct 23 2008 2:11 am

    Great Post! Very helpful!

    Cheers!

  58. Imokon / Oct 31 2008 7:11 pm

    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
        
    
      
        
          &lt;input type="text" name="j[memberName]" value=""&gt;
          Name
        
        
        
          
          Password
        
        
        
          
          Password (Again)
        
        
        
          &lt;input type="text" name="j[memberEmail]" value=""&gt;
          Email Address
        
     
        
           display email address
        
        
           hide email address
        
    &lt;? } if( $_HIVEID['captcha'] ){
      print "  \n".
            "    \n".
            "    \n".
            "  \n";
    }
    ?&gt;
      
      
      
        Membership Details
     
        
          
          Country
        
     
        
          &lt;input type="text" name="j[memberURL]" value=""&gt;
          URL
        
     
        
          &lt;input type="text" name="j[memberCodeURL]" value=""&gt;
          Code URL
        
     
        
          &lt;input type="text" name="j[memberTxt1]" value=""&gt;
          Site Name
        
     
        
          &lt;input type="text" name="j[memberTxt2]" value=""&gt;
          
        
     
        
          
          Site Description
        
     
        
          
          Comment
        
    
      
      
      
        Submit
        
          
        
      
      
    
    
    
      Join
      
        Thank you for your submission, </strong></strong>. You should be added in the
        next update.
      
    
    
    
  59. Imokon / Oct 31 2008 7:13 pm

    Man that totally butchered the code… the join form I am using is from this website;
    http://skode.void-star.net/projects/vs.hive/

  60. Chris / Nov 20 2008 11:01 am

    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.

  61. Laurie / Nov 30 2008 6:45 am

    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

  62. Laurie / Nov 30 2008 7:07 am

    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,

  63. morgan / Dec 17 2008 2:08 pm

    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

  64. inko9nito / Dec 17 2008 2:15 pm

    @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.

  65. atomicj / Jan 8 2009 10:22 pm

    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

  66. Dennis / Feb 6 2009 2:58 pm

    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?

  67. Jason / Feb 7 2009 11:48 am

    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…

  68. inko9nito / Feb 7 2009 4:26 pm

    @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/

  69. Dennis / Feb 7 2009 6:30 pm

    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.

  70. Cesar / Feb 17 2009 12:23 am

    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

  71. Pia Oliver / Feb 22 2009 9:12 pm

    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

  72. Nadia M. / Feb 24 2009 1:17 pm

    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

  73. Travis / Feb 24 2009 5:21 pm

    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

  74. Kristan / Feb 25 2009 9:55 am

    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

  75. you and me / Feb 26 2009 1:21 am

    hi capthcha is is soooooooooo

    great

  76. Vera K. / Feb 27 2009 3:14 am

    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!

  77. Abhishek / Feb 27 2009 4:36 am

    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

  78. Vladislav / Feb 27 2009 7:44 am

    Thanks for info. Very helpful!!

  79. eglence / Feb 28 2009 1:07 pm

    i installed the script but – captcha is not seen on the page. Nothing wrong but coulndt understand what the problem is…

  80. SVP / Mar 1 2009 12:53 pm

    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.

  81. Lori / Mar 3 2009 2:50 pm

    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

  82. Mat / Mar 4 2009 2:55 pm

    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 . “)”);
    }
    ?>

    • Erda / May 18 2009 12:41 pm

      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?

      • Kenzo / Jun 27 2010 1:50 am

        I run the captcha on a site that only has an index.php and two pages with forms. The forms post to $php_self and then at the top of the file I control how the captcha works by evaluating the URL and a hidden input field.

      • Keith / Jun 27 2010 10:57 am

        The single-file method is actually probably a lot more secure, in my opinion, and it is a very common way for PHP programmers to configure a form submit/process algorithm.

        For that reason, I built a fairly simple demo of reCAPTCHA using that scenario. Feel free to take a look if it helps.

        http://www.spectrum-nashville.com/reCAPTCHA/demo.php

        The form and processing code are all in one PHP file. The source is available to download as a ZIP file if you need to take a closer look.

        Enjoy!

  83. Ambassades / Mar 5 2009 9:46 am

    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

  84. Boo Rody / Mar 5 2009 8:29 pm

    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

  85. spiritman / Mar 7 2009 9:28 am

    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.

  86. spiritman / Mar 7 2009 9:53 am

    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!

    • inko9nito / Mar 7 2009 3:56 pm

      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?

  87. Boo Rody / Mar 7 2009 4:07 pm

    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 “

  88. Boo Rody / Mar 7 2009 4:09 pm

    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

    • inko9nito / Mar 7 2009 4:13 pm

      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.

  89. Garfee / Mar 7 2009 6:22 pm

    Great tutorial.

    Thanks man.

  90. spiritman / Mar 7 2009 10:52 pm

    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?

  91. spiritman / Mar 7 2009 10:56 pm

    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.

  92. Boo Rody / Mar 11 2009 11:45 am

    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.

  93. Boo Rody / Mar 11 2009 12:01 pm

    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

  94. Renita / Mar 12 2009 3:09 pm

    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?

  95. Adrian / Mar 13 2009 12:43 pm

    Thanks, it´s really a good tutorial.

    I search in other`s web sites, but they only consfused my.

  96. Vic Fricke / Mar 14 2009 2:48 pm

    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?

  97. Boo Rody / Mar 15 2009 9:00 am

    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

  98. inko9nito / Mar 17 2009 5:43 am

    So sorry guys, I’m completely swamped and don’t have time to help you out with this stuff right now 😦

  99. Boo Rody / Mar 17 2009 8:29 am

    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

  100. Bob / Mar 17 2009 7:05 pm

    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.

  101. passionent / Mar 23 2009 7:25 pm

    Hi can any1 help me w.this cant seem to be able to enter php text on our web

  102. Ethan / Mar 26 2009 2:27 pm

    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?

  103. oyun / Mar 27 2009 10:31 am

    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.

  104. Dunc / Mar 31 2009 12:46 pm

    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!!

  105. Tom / Apr 1 2009 7:59 am

    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.

    • Claudia / Aug 5 2009 5:19 pm

      I am having the exact same issue. Did you ever get a solution/reply back?
      thanks
      Claudia

  106. gabe / Apr 3 2009 8:10 pm

    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.

  107. inko9nito / Apr 5 2009 1:38 am

    @gabe you need to set that in the mail header:

    $header = “From: $email”;
    mail($to, $subject, $message, $header);

  108. siirt / Apr 6 2009 2:20 am

    thanks you

  109. sıcak videolar / Apr 6 2009 2:21 am

    sicak videolar izle

  110. Elizabeth K. Barone / Apr 6 2009 2:29 pm

    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!

  111. Eladine / Apr 7 2009 11:49 am

    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. 🙂

  112. Mike Naeseth / Apr 9 2009 2:33 pm

    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

  113. Mike Naeseth / Apr 9 2009 2:59 pm

    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.

    • Eli / Apr 20 2010 11:38 pm

      Can you please send me samples of your form using recaptcha for loggin in as well as Contact Us forms? I saw your posting and I am in dire need of help. My site was attacked by not having the captcha working correctly.

      Please let me know any help you can give me, thanks a lot!

      • Keith N. / Apr 21 2010 8:47 am

        I don’t know if Mike still monitors this blog or even has the same email address, so I thought I’d point this out just in case.

        I posted a pretty complete code example nearer the bottom of this blog (search for “!CORRECTIONS!”) and read the exchange of ideas there.

        For a login form, just put your login code in place of the contact form. Or, for that matter, put any other code in place of the contact form (database update, sendmail, etc.). The example is really very generalized and it is all there….

        Good luck,
        – K

  114. Mike Naeseth / Apr 9 2009 3:02 pm

    Sorry, didnt know the email address wasnt shown on the posts. my email address is:

    michaelnaeseth@yahoo.com

  115. Mike Naeseth / Apr 9 2009 3:24 pm

    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.

  116. inko9nito / Apr 9 2009 10:07 pm

    @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.

  117. Mike Naeseth / Apr 9 2009 11:00 pm

    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.

  118. Jack / Apr 16 2009 8:05 am

    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!

  119. Cynthia / Apr 17 2009 12:48 pm

    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.

  120. Cynthia / Apr 17 2009 1:17 pm

    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!

  121. Mike / Apr 20 2009 3:37 pm

    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?

  122. Cynthia / Apr 20 2009 4:21 pm

    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 name attribute 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);

    ?>

  123. thepoisongarden / Apr 21 2009 9:51 am

    Just to say, thanks very much for this very helpful information. I’ve successfully installed reCaptcha on one site; five to go.

  124. marketking / Apr 24 2009 6:55 pm

    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

  125. spirit / Apr 26 2009 9:40 pm

    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.

  126. Roope / Apr 27 2009 5:29 am

    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!

  127. DemiGoth / Apr 30 2009 4:34 am

    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…

  128. can u make it for me? / Apr 30 2009 12:42 pm

    can u make it for me? i cant understand after the “”zip”” something..please…help me..please…tnx…good luck

  129. can u make it for me? / Apr 30 2009 1:29 pm

    wat will i do if i put captcah in my testimonial in my friendster??? nid help

  130. TheNightOwl / May 2 2009 6:37 am

    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.

  131. chulini / May 4 2009 10:19 pm

    :O!!
    muchas gracias, te pasaste.
    está clarito.
    me funcionó inediatamente 🙂

  132. Mathew / May 9 2009 9:44 am

    @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

    • inko9nito / May 9 2009 12:40 pm

      @Mathew thank you so much for doing this. I just don’t have the time anymore.

    • DemiGoth / May 26 2009 7:05 am

      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…

  133. Cynthia / May 9 2009 10:27 am

    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.

  134. Michael Gandy / May 11 2009 11:02 am

    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!

  135. Connie Harrison / May 12 2009 3:45 pm

    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?

    • inko9nito / May 12 2009 5:57 pm

      reCAPTCHA only checks one word.

  136. Connie Harrison / May 12 2009 6:47 pm

    Ok. But it still logs the member in even if both words are incorrectly spelled?

    • inko9nito / May 13 2009 12:29 am

      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.

  137. Genji / May 13 2009 7:09 pm

    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

    • Rob / Jun 12 2009 5:43 am

      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

  138. my PC Techs / May 14 2009 12:15 am

    Thanks for the easy to follow instructions.

  139. Faith / May 14 2009 11:35 pm

    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?

  140. John / May 15 2009 6:56 pm

    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?

  141. John / May 15 2009 7:00 pm

    Can I pay you to fix my two pages so this works?

  142. Srivatsan / May 16 2009 12:11 pm

    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

  143. Chris / May 17 2009 10:41 am

    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.

  144. Mike / May 17 2009 6:11 pm

    I can not for the life of me get the Captcha image to show on my website

  145. John / May 18 2009 6:52 pm

    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

  146. John / May 18 2009 6:54 pm
  147. John / May 18 2009 7:05 pm

    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?

  148. Michael / May 18 2009 8:28 pm

    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

  149. Mike / May 19 2009 8:20 am

    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.

  150. paddster7 / May 20 2009 3:19 pm

    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!

    • paddster7 / May 20 2009 3:25 pm

      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.

      • paddster7 / May 20 2009 3:26 pm

        Well, that did not work either. Let me try this – I am trying to specify the <><> html tags in my original post.

      • paddster7 / May 20 2009 3:29 pm

        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.

  151. David / May 20 2009 4:36 pm

    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!

  152. David / May 20 2009 4:38 pm

    From my above post the form action should read.

    <form action="”

  153. David / May 20 2009 4:40 pm

    <form action="php echo $editFormAction;" Ok, with <?

  154. arif / May 24 2009 6:14 am

    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.

  155. arif / May 24 2009 6:15 am

    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.

  156. arif / May 24 2009 2:10 pm

    ******* 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.

  157. Ursa / May 24 2009 3:40 pm

    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

  158. Ursa / May 26 2009 12:47 pm

    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!

  159. austin / May 27 2009 12:16 pm

    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-

    • Quirk / Jun 3 2009 10:50 pm

      Make the error message a popup instead of new page….

  160. Dan / May 27 2009 12:55 pm

    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,

  161. Kristan / May 27 2009 1:31 pm

    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

  162. Mewis / Jun 2 2009 10:07 am

    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. ; _;

  163. Quirk / Jun 3 2009 10:47 pm

    Brilliant, your help got me all installed in less than 5 mins. Thanks

  164. inko9nito / Jun 3 2009 10:52 pm

    @Mewis your actual private key string goes inside the quotes instead of the ellipsis (…)

  165. Graeme Burrell / Jun 6 2009 7:27 am

    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

  166. sirus / Jun 7 2009 2:43 pm

    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

  167. sirus / Jun 7 2009 3:09 pm

    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

  168. Brendon / Jun 9 2009 12:56 am

    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.

  169. Rob / Jun 9 2009 7:39 pm

    @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

  170. Victor / Jun 10 2009 4:13 pm

    @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

  171. Victor / Jun 10 2009 4:18 pm

    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.

    • Janice Brown / Jun 18 2009 5:14 pm

      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.

  172. josh909 / Jun 15 2009 1:44 am

    Great post – i followed your instructions and everything worked without a hitch!

  173. Janice Brown / Jun 18 2009 1:42 pm

    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.

  174. Janice Brown / Jun 18 2009 1:44 pm

    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?

  175. Sabrina / Jun 23 2009 3:37 pm

    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.

  176. Sabrina / Jun 23 2009 3:50 pm

    Ok. Now that’s fixed, but I’m getting a Page Not Found message after I click Submit. Any ideas?

    Thanks

  177. Mike / Jun 27 2009 10:03 pm

    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”);
    }

  178. Mike / Jun 27 2009 10:08 pm

    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”);
    }

  179. Mike / Jun 27 2009 10:11 pm

    @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

  180. Hannah / Jul 5 2009 1:48 pm

    Hi, thank you so much for writing this guide. I think i have the recaptcha working as i’m not getting any error messages. However, for some reason my email is not coming through. If anyone could have a look at my code to see if they can spot something i have done wrong, i would be very grateful.

    sendmail.php file:

    is_valid) {
    header(“location:captcha_error.php”);
    die();
    }

    $name = $_REQUEST[‘name’] ;
    $email = $_REQUEST[’email’] ;
    $tel = $_REQUEST[‘tel’] ;
    $message = $_REQUEST[‘message’] ;

    if (!isset($_REQUEST[’email’])) {
    header( “Location: http://www.picturemybaby.co.uk/contact.php” );
    }
    elseif (empty($name) || empty($email) || empty($message)) {
    header( “Location: http://www.picturemybaby.co.uk/error.html” );
    }
    else {
    mail( “hello@picturemybaby.co.uk”, “PMB contact form message”,
    $message, “From: $name “, “Tel. number: $tel” );
    header( “Location: http://www.picturemybaby.co.uk/thankyou.html” );
    }
    ?>

  181. Hannah / Jul 5 2009 2:10 pm

    Sorry, this is the whole code:

    is_valid) {
    header(“location:captcha_error.php”);
    die();
    }

    $name = $_REQUEST[‘name’] ;
    $email = $_REQUEST[’email’] ;
    $tel = $_REQUEST[‘tel’] ;
    $message = $_REQUEST[‘message’] ;

    if (!isset($_REQUEST[’email’])) {
    header( “Location: http://www.picturemybaby.co.uk/contact.php” );
    }
    elseif (empty($name) || empty($email) || empty($message)) {
    header( “Location: http://www.picturemybaby.co.uk/error.html” );
    }
    else {
    mail( “hello@picturemybaby.co.uk”, “PMB contact form message”,
    $message, “From: $name “, “Tel. number: $tel” );
    header( “Location: http://www.picturemybaby.co.uk/thankyou.html” );
    }
    ?>

  182. Tyler / Jul 14 2009 8:25 pm

    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?

  183. kniese / Jul 15 2009 9:25 am

    custimizing ReCaptcha and thus getting rid of the buttons, more here:
    http://recaptcha.net/apidocs/captcha/client.html “Look & Feel Customization”

  184. Karl / Jul 17 2009 5:26 pm

    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();
    }
    }

    }
    ?>

  185. Karl / Jul 17 2009 5:31 pm

    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

  186. Glenn / Jul 21 2009 9:35 pm

    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

  187. Max / Jul 23 2009 11:16 am

    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.

  188. Max / Jul 23 2009 3:35 pm

    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!

  189. Max / Jul 24 2009 8:48 am

    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?

  190. Max / Jul 24 2009 9:50 am

    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” );

  191. Azram / Jul 27 2009 10:33 am

    hi

    just one question ?

    How do i keep the field write’s when there are errors in recaptcha ?

    thx

    az’

  192. Jeremy / Jul 30 2009 1:04 pm

    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?

  193. daily1game / Aug 2 2009 12:37 am

    Hi,
    Thank you Very much! It was really helpful. I am using recaptcha on my contact form. Its more secure now!

  194. aLexa / Aug 2 2009 7:32 pm

    Great stuff!!! Thanks once again!!!

  195. Allison / Aug 3 2009 11:02 am

    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!!

  196. Nick / Aug 3 2009 8:06 pm

    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.

    • Zaiber / Aug 4 2009 3:16 pm

      Your link to ad2phoenix.com is not available… it seems so…

  197. Claudia / Aug 6 2009 8:53 am

    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

  198. Snow / Aug 6 2009 9:27 am

    Thank you very much! This works great!

  199. Kris / Aug 11 2009 12:01 pm

    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.

  200. Jodi / Aug 12 2009 8:02 am

    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

    • Jodi / Aug 12 2009 9:51 am

      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.

      • Dennis / Jul 25 2010 8:36 pm

        that was it had to take it out of the table would never had thought of that its ridiculous lol
        Thnx alot

  201. Robert Anderson / Aug 13 2009 11:32 pm

    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?

  202. Mike Dean / Aug 15 2009 7:51 pm

    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?

    • Ronald / Mar 10 2010 9:53 am

      Hi Dean, how did you get reCaptcha to work? I always receive the following error: (reCAPTCHA said: incorrect-captcha-sol)
      Please advise. Thx!

  203. jagdish / Aug 16 2009 12:23 am

    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.

  204. Ben / Aug 17 2009 8:01 am

    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’];)

    • Jodi / Aug 17 2009 8:25 am

      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

      • Ben / Aug 17 2009 8:04 pm

        Thanks. Do I put the reCAPTCHA code at the beginning? It doesn’t work for me.

        • Jodi / Aug 18 2009 7:43 am

          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

          • Jodi / Aug 18 2009 7:46 am

            That didn’t copy right into the form let me try it again.

  205. Jodi / Aug 18 2009 7:54 am

    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.

  206. hosterware / Aug 18 2009 2:16 pm

    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

  207. Steve Fruitt / Aug 23 2009 6:05 pm

    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?

  208. Steve Fruitt / Aug 23 2009 6:41 pm

    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.

  209. Arpan / Aug 31 2009 8:09 am

    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..!

  210. James Hackett / Aug 31 2009 8:11 am

    Check out fancy captcha on this website

    https://www.hosterware.com/contact_us.html

    looks well cool

    • craftymomma / Sep 29 2009 3:54 am

      James,

      Turn off your javascript and see what happens to that Captcha.

  211. elizabeth / Sep 10 2009 12:02 pm

    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

  212. Susie Price / Sep 12 2009 10:10 am

    I appreciate you might have got a bit bored with answering questions on this post but I’ve scanned through all the Cahptcha is not actually appearing on their form and I’m having the same problem. My form name is http://www.susiestravelweb.com/Contact/contact.php and the send file is http://www.susiestravelweb.com/Contact/send.php. Any guidance you can give would be much appreciated.

  213. miroune / Sep 14 2009 1:07 pm

    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

  214. Al / Sep 15 2009 2:24 am

    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?

  215. Al / Sep 15 2009 2:32 am

    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?

  216. Al / Sep 15 2009 2:34 am

    I had to eliminate the “” from previous message so it would show full code.

  217. Al / Sep 16 2009 8:15 pm

    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

  218. Al / Sep 16 2009 8:17 pm

    half the code didn’t post above, send me an e-mail mediawebpad@aol.com

  219. Scott / Sep 17 2009 3:16 pm

    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.

  220. John C / Sep 20 2009 7:33 am

    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

  221. DarkKnight / Sep 23 2009 12:12 am

    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

  222. Frank / Sep 24 2009 12:29 pm

    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.

  223. James S / Sep 25 2009 2:18 pm

    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?

    • James S / Sep 29 2009 9:40 am

      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.

  224. JasonD / Sep 28 2009 4:47 am

    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.

  225. vanrick / Sep 28 2009 12:55 pm

    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

  226. Youthman / Oct 1 2009 10:08 pm

    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.

  227. unique / Oct 5 2009 5:14 am

    hi,

    Recaptcha not workign in firefox, working well in IE 8.

    any suggestions.

    • Jodi / Oct 5 2009 7:56 am

      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.

  228. Peter / Oct 7 2009 8:03 pm

    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?

  229. Cesar / Oct 8 2009 3:58 am

    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.

  230. Gerschel / Oct 10 2009 12:25 pm

    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.

  231. divx film indir / Oct 18 2009 6:14 pm

    I’ve got the reCaptcha working just fine. Thanks for a very useful tutorial. it is working mozilla and ie

  232. James Veal / Oct 20 2009 11:19 am

    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

  233. saikumar / Oct 29 2009 5:25 am

    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 );
    ?>

    • vanrick / Oct 29 2009 12:54 pm

      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.

  234. gatolandia / Oct 30 2009 7:31 pm

    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

  235. Chad / Nov 6 2009 10:43 am

    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.

  236. john / Nov 6 2009 5:35 pm

    where is reCapcha on this site?

  237. Ryan / Nov 8 2009 6:06 pm

    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

  238. Ryan / Nov 8 2009 6:07 pm

    got cut out… my form action call to “dynamic variables, dynamic variables”

  239. iQuest Web Design / Nov 12 2009 4:35 pm

    You have done a great job in explaining and how to install reCaptch.

  240. Javi / Nov 17 2009 7:12 am

    Hi, I have one quest: how many .php files are neccessary in my server? I have done everything you said in this tutorial and it almost works fine… but when I type the characters shown in the recaptcha (and all the characters introduced are fine), my page is redirected to http://www.myweb.com/RECAPTCHALIB.PHP??? why is that??
    I am not programmer and I am a little lost, I have uploaded 3 .php files to my server (and all of them are in the same plac, not in different folder): “FORM.PHP” + “PROCESS.PHP” + RECAPTCHALIB.PHP”… here´s my doubt… are the 3 files necessary?? what am I doing wrong?
    _________________________________________________

    My form mail.php has this code before the submit button:

    _________________________________________________

    The procces.php file´s code is:

    is_valid) {
    die (“The reCAPTCHA wasn’t entered correctly. Go back and try it again.” .
    “(reCAPTCHA said: ” . $resp->error . “)”);
    }
    ?>
    _________________________________________

    And finally, the recaptchalib.php´s code is the same as it was at first, I have not edited anything in this code….

    Please, could someone help me?
    best regards
    Javi

  241. Javi / Nov 17 2009 7:15 am

    Sorry,the codes are:

    form.php:

    ______________________________________________

    process.php:

    is_valid) {
    die (“The reCAPTCHA wasn’t entered correctly. Go back and try it again.” .
    “(reCAPTCHA said: ” . $resp->error . “)”);
    }
    ?>

    Thank you in advance

  242. Javi / Nov 17 2009 7:17 am

    process.php code:
    require_once(‘recaptchalib.php’);
    $publickey = “6LesbgkAAAAAAB6JI6dRdVbZ-xWGxzGJ2tllBdsM”; // you got this from the signup page
    echo recaptcha_get_html($publickey);
    _________________________________
    form.php:
    require_once(‘recaptchalib.php’);
    $privatekey = “6LesbgkAAAAAAF56Dn9xiYebdrmPFfY0w4_vz3lw”;
    $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 . “)”);
    }

  243. Nessaia / Nov 17 2009 8:32 am

    Well, where can I change the “Type the two words” sentence? I´d like to have it in german…

  244. Nessaia / Nov 17 2009 9:04 am

    whoops, i find some mistakes:

    even if i fill out the recptcha with the wrong answers the mail is sending!! This also is by any Pages which where so lucky postet over here…. i tested it!
    When i fill out the form with the wrong answers the mail DONT shall send, isnt it so? Whats the failure in here?

  245. James / Nov 17 2009 9:07 am

    Hi, are you using a html or wordpress website plugin

  246. Nessaia / Nov 17 2009 10:33 am
  247. Javi / Nov 18 2009 6:21 am

    Waauuooh! I have finally got my recaptcha works!! but I only have a trouble: the form is not sent to my email…. which can be the solution to this one??
    best regards and thank a lot to everyone, specially to inco9nito. great work!

  248. Mark / Nov 18 2009 6:55 am

    Hi there, wonderful post!

    Just one quick question, On the reCAPTCHA example I first used it had a self contained display message that kept you on the same page when the form is submitted and there was an error.

    Are you fimiliar with this design and do you know how to modify the existing code so that this message is displayed and doens’t take you through to another page.

    Kindest Regards,

    Mark

  249. Rajat Kapoor / Nov 19 2009 7:51 am

    Hii, thanks for such a wonderful script and step by step instructions.

    Everything is fine i just want to know, i have few forms in HTML pages, can i use reCaptcha in HTML pages.

    and reCaptcha is exceeding over my form size, how can i change its width and height

    thanks

    I have used this code in the following page:
    http://udayraj.com/33_pages.php

  250. Tarik / Nov 23 2009 4:22 pm

    Pls goin into my site… I prepear for you great work….

  251. Vishal / Dec 1 2009 4:04 am

    I hope one day recaptcha guys will learn how to write tutorial after reading this post. Simple & clean great work. Thanks

  252. Dorothy / Dec 2 2009 11:14 am

    Hi there!
    Great tutorial! Thank you for posting it on the web. I just have a quick question – i have one php file with the php form and php process code in it. I’ve added the code for the php form and tried to add the process code in various different places, but when i do i get :The reCAPTCHA wasn’t entered correctly. Go back and try it again.(reCAPTCHA said: incorrect-captcha-sol) some where on the form before it’s even been sent. Do you have suggestions.

    Thank you in advance!

  253. Tracey / Dec 2 2009 10:24 pm

    Hello,
    Great tutorial…but how can I get rid of the blue voice button? When you click on it there is no way to turn it off.

  254. BBunny / Dec 4 2009 9:24 am

    For some reason the recaptcha works on my local host but not when it goes live? What could be the reason? ON the live site it does not display anything and also the page is rendered to the point where captcha code is, but not beyond that. Please help.

  255. Pramod / Dec 5 2009 12:58 pm

    Thanks a lot, i was struggling a lot to implement recaptcha. but ur post made it very easy.

  256. Dave / Dec 6 2009 12:56 pm

    Can I add my thanks to the many others, saved me a lot of work

  257. Chi / Dec 8 2009 1:32 pm

    This is a great post, but my problem is: I typed in all the infomation you provided, but the code shows up as ‘PHP’ on the desig and when I come to preview the page, it doesnt show the ReCAPTCHA box. Do you know what’s going wrong?

    Chi~

  258. natalio / Dec 9 2009 1:44 pm

    Good post¡¡

  259. ELISF / Dec 14 2009 3:01 pm

    I’m having trouble with my “process.php” form….is there something I’m not seeing here?

    is_valid) {
    // What happens when the CAPTCHA was entered incorrectly
    die (“The reCAPTCHA wasn’t entered correctly. Go back and try it again.” .
    “(reCAPTCHA said: ” . $resp->error . “)”);
    } else if($resp->is_valid) {
    header(“location:submitted.php”);
    }
    ?>

    <?php
    $request_method = $_SERVER["REQUEST_METHOD"];
    if($request_method == "GET"){
    $query_vars = $_GET;
    } elseif ($request_method == "POST"){
    $query_vars = $_POST;
    }
    reset($query_vars);
    $t = date("U");

    $file = $_SERVER['DOCUMENT_ROOT'] . "/../data/gdform_" . $t;
    $fp = fopen($file,"w");
    while (list ($key, $val) = each ($query_vars)) {
    fputs($fp,"\n”);
    fputs($fp,”$val\n”);
    fputs($fp,”\n”);
    if ($key == “redirect”) { $landing_page = $val;}
    }
    fclose($fp);
    if ($landing_page != “”){
    header(“Location: http://“.$_SERVER[“HTTP_HOST”].”/$landing_page”);
    } else {
    header(“Location: http://“.$_SERVER[“HTTP_HOST”].”/”);
    }
    ?>

    • ELISF / Dec 14 2009 3:02 pm

      P.S. The top part of the php code was cut off of the previous message…I’m thinking there is something wrong with the header.

      • ELISF / Dec 14 2009 3:04 pm

        I’m getting this error message:

        Warning: Cannot modify header information – headers already sent by (output started at /home/content/e/l/i/elisf/html/gdform.php:1) in /home/content/e/l/i/elisf/html/gdform.php on line 14

  260. Ralph Tomaccio / Dec 20 2009 12:09 pm

    I’d like to use reCaptcha on my two web site forms but know little to nothing about code. My first question is how do I determine whether I should be using PHP or one of the other instructions?

  261. Benji / Dec 22 2009 10:27 pm

    You seem to have a very good grip on the instructions on implementing Captcha on websites. However, I am stumped at the point where you say that my form needs to be PHP as well as the processing file. I have created the PHP script based on thesitewizards instructions – however, I am using Dreamweaver to create all this stuff. I created my form in html but changed the extension to php afterward – as I read that you suggested. However, once the form is submitted, the page gets redirected correctly yet no emails are received. Any hints on this? I have searched and searched for instructions on PHP within Dreamweaver but to no avail. Any help is VERY appreciated! Merry Christmas!

  262. Benji / Dec 22 2009 10:59 pm

    I fixed the php issue. It was actually with the script that I had create from thesitewizard. If anyone else has this issue, may I suggest using the “PHP Script for processing the form results” listed on this link: http://www.dreamweaverclub.com/dreamweaver-php-form.php . This was an awesome discovery for those of you using Dreamweaver! All you need to do is change your custom created form file from html to php (as suggested within this blog) and create a second “process.php” file using the above script. You will only need to edit four field in the php process file and they are clearly marked! Now that my form is working properly, I’m off to implement the Captcha…

  263. Benji / Dec 22 2009 11:38 pm

    OK. The Captcha does work with your instructions but I had to modify my “process.php” script because i was getting an error page that said: Name of form element recaptcha_challenge_field cannot be longer than 20 characters. I changed the line in the script that said //if ($j >= 25)// from 25 to 50. It seems to be working except that the feedback I receive includes the recaptcha_challenge field followed by a very long string of characters and the recaptcha_response field followed by the actual answer that was entered into the captcha. I suppose this is ok but I’m going to attempt to not send that info in the results to the email.

  264. DarkKnight / Dec 31 2009 12:04 am

    Okay, got the widget working beautifully.

    However, if the result is valid, I want to display a new page with links that are being hidden from scanning. So I don’t want the links page to be searchable unless the ReCaptcha result is valid.

    Any ideas?

  265. Grant / Jan 3 2010 5:39 am

    Thank you sooo much. Wonderfully helpful

  266. Jerry / Jan 3 2010 3:15 pm

    I have followed the instructions but get the following error code in Dreamweaver “Live View:
    The reCAPTCHA wasn’t entered correctly. Go back and try it again.(reCAPTCHA said: incorrect-captcha-sol)
    I get the same message on a testing server.

    • Haris / Jan 5 2010 4:20 pm

      did you include the library and the path of its direcory correctly?

  267. Jeff Wragg / Jan 4 2010 2:49 pm

    I checked about a dozen pages linked from the comments above and every single one of them solved the recaptcha problem using javascript, not php. I’m concerned that they gave up on php, something I’m tending towards now.

    Your site was a big help to me getting going, but I still have troubles.

    • Jeff Wragg / Jan 8 2010 5:13 am

      I’ve worked more on it, and received information from a programmer who spent a lot of time trying to get this to work. We both have the same problem. It seems to install, seems to work, but actually accepts any response input as valid.

      So, that, along with the apparent defection of many users to javascript, I hereby quit trying to use this. There is something subtle, but very wrong here.

  268. Kam / Jan 4 2010 8:54 pm

    I can get this all working but I am unable to incorporate the recaptcha with a form.

    I am trying to collect info from viewers. Info like email, phone#, address, etc and authenticate it by using recaptcha but am at a loss on how to do this.

    I can view the captcha, and the proper pages work if entered correctly and incorrectly but none of the form info gets sent to me.

    can anyone help..?

  269. Lynne / Jan 5 2010 2:31 pm

    Thank you! Have tried multiple times, but think it’s finally working. Woudn’t have had a chance without your help.

  270. SuNG / Jan 7 2010 11:18 pm

    Thank you very muchhhhhhhhhhhhhhhhhhhhh

    =)

  271. DarkKnight / Jan 8 2010 11:38 am

    Kam,

    I put reCaptcha on a challenge page before visitors enter information. It refers them to a page that lets them select which form of feedback they wish to leave (I have various feedback forms).

  272. Danny / Jan 9 2010 1:27 am

    Thanks for the great post!

    I have no php skills whatsoever but managed to get a contact form with recaptcha up on my site in no time at all.

    Cheers,
    Danny

  273. Bharanidharan / Jan 10 2010 10:12 am

    Hi, does this works only in hosted server? When i try to run up from my localhost, i am getting all the captcha entry as wrong. What wrong with me?
    I have done all the things set with the post. form.php with public key and process.php with private key.

  274. norman golub / Jan 10 2010 2:28 pm

    cancel this captcha for me. i am tired of decoding your mixed words and numbers.

    norm golub

  275. xav / Jan 11 2010 5:25 am

    hello

    I am trying to implement the captcha

    I get to the correct display but i don’t have a process file so i don’t know where i should insert the code with the private key

    My form in done in htm and called from withing a php template page.

    thanks for help

    xav

  276. Erich / Jan 11 2010 1:42 pm

    1st, your patience is to be commended.
    I’m not that familiar with php and the implementation of recaptcha, and I have a sort of fundamental question:

    First, I would like to use the recaptcha simply to securely access a page, with password, with the recaptcha being part of the key, and not connected to a form. If this is possible, is code modification required within the recaptchalib.php file?

    Secondly, is it also possible to embed the recaptcha code within an alert box, to accomplish the above?

    Thanks.

  277. Terry / Jan 12 2010 3:38 pm

    The contact_us.php page in the main catalog directory seems to be OK, but I’m having trouble with the process page which resides in the includes/languages/english folder.

    Whenever I press the contact link and the page in the above mentioned folder is there (using the code you provided for the process page), I get “The reCAPTCHA wasn’t entered correctly. Go back and try it again.(reCAPTCHA said: incorrect-captcha-sol)” You don’t even get a chance to see the reCaptcha!

    If I use my old process page, it goes right to the form and while everything looks OK, it will not verify the reCaptcha. You can type in any old thing and it just goes through. I have no idea what the problem is or if you can help me, but I would appreciate any and all input! Thank you!

  278. David / Jan 15 2010 1:43 pm

    Hi
    I have just installed the recaptcha and it works fine but will not send the form to more than one email address, any suggestions please.

    I need it to submit the form and send the results to 2 email address.

    Thanks
    David

  279. WWD / Jan 15 2010 1:59 pm

    After successfully passing the challenge, the response deposits the visitor at a web page with different e-mail links to select. That was my down-and-dirty solution. I had struggled with installing it on multiple pages without any success of my own, so I decided to simplify.

  280. thaproxinator / Jan 19 2010 6:16 am

    thankyou very much for this tutorial.

    well explained. 🙂

  281. Viewmountain / Jan 19 2010 11:06 am

    Mine works perfectly.

  282. Terry / Jan 19 2010 11:16 am

    Who cares?!?!?

  283. Tomasz / Jan 20 2010 4:30 am

    Great post! You help me! Thanks a lot! 🙂

  284. Keith / Jan 23 2010 5:10 pm

    Firefox problem. Thanks for that little tidbit. I had been struggling with the reCAPTCHA half the day. Worked great under IE, but would not validate with FF.
    I had :
    table
    form
    …rows, columns, fields, CAPTCHA…
    /form
    /table
    in my code originally.
    I changed it to:
    form
    table
    …rows, columns, fields, CAPTCHA…
    /table
    /form

    and sure enough, it works great under FF and IE both just fine.
    Thanks again particularly to Jody for bringing the “fix” back to this post.

    • Jim / Mar 19 2010 10:40 pm

      THANKS!
      THAT was what I was looking for!!!
      I’ve been trying to figure out why this was happening for the past 3 hours.

      I moved the “form” tags outside of the “table” tags and VIOLA! It’s working like a charm.

  285. Paul / Jan 23 2010 5:20 pm

    I found your blog much easier to follow than the captcha website. Unfortunately I’m getting “Forbidden – 403” when I hit the send button on my completed form which I obtained from thesitewizard. I’m not seeing this problem from anyone before me. Can you guide me to how to fix. I do seem to be connected to captcha because my challenge words are changing. Thank you for helping all of us beginners.

  286. I Am WEC / Jan 26 2010 9:52 am

    Thanks a ton for this article! I have been working on implementing reCAPTCHA on my contact form for ages because I’ve gotten a lot of spam and actually had to take it down at one point it got so bad. This article is probably the best article on this subject, even better than the one on reCAPTCHA’s site! Great job!

  287. Lee / Jan 29 2010 11:40 pm

    Thanks for your article! It was very helpful. It works but I do not get the error page for thankyou page. Once I submit the message, it goes start back to home page. I will keep working on it to get it right.

  288. Lee / Jan 30 2010 4:56 am

    I still cannot get the recaptchalib.php to work. Every thing is ok on the contact us page. However, when I submit comment for test, I get Fatal error: Call to undefined function recaptcha_check_answer() in…

    is_valid) {
    die (“The reCAPTCHA wasn’t entered correctly. Go back and try it again.” .
    “(reCAPTCHA said: ” . $resp->error . “)”);
    }
    ?>

    Can anyone assist me? I really need to get this working to stop the spammers!

    Lee

  289. Lee / Jan 30 2010 4:57 am

    is_valid) {
    die (“The reCAPTCHA wasn’t entered correctly. Go back and try it again.” .
    “(reCAPTCHA said: ” . $resp->error . “)”);
    }
    ?>

    Lee

  290. sushant / Jan 30 2010 7:27 am

    Error shown:The reCAPTCHA wasn’t entered correctly. Go back and try it again.(reCAPTCHA said: incorrect-captcha-sol)

  291. Lee / Jan 30 2010 7:33 am

    After about a day trying to get recaptcha to work, I give up. I think I will look for another captcha that’s works.

  292. Juniper / Jan 30 2010 8:39 am

    @Lee: Don’t give up too quickly; this package works nicely.

    Go back to the recaptcha plugin page for PHP:
    http://recaptcha.net/plugins/php/
    and read the 2 script clips they show there. It can’t be much simpler than that, really. Less than 10 lines of php and it will work.

    The only possible caveat for getting started: don’t put the captcha in a table to start with, and it will work.

  293. Lee / Jan 30 2010 9:02 pm

    I will give it another go. This is what I have done.

    Created the Form Code – it works.

    I downloaded the feedback.php with private and public keys.

    I downloaded recaptchalib.php. All files are in the same directory.

    I can send comments but the recaptcha does not work.

    Am I missing something here.

  294. Lee / Jan 30 2010 9:07 pm

    After another read of http://recaptcha.nte/plugins/php/ I gather I am not putting the 2 script clips in the right place.

    I assume they go into recaptchalib.php.

    Is this correct?

    If so, where do I place it in the recaptchalib.php file?

  295. Lee / Jan 30 2010 10:51 pm

    Well, I have had another go. However, it seems that all works except it will not send the comments to the email address. I used sitewizzard.com to set up form code for web page (by the way, it is contact-us.html) and feedback.php. I downloaded recaptchalib.php and entered the code script required. Both feedback.php and recaptchalib.php are in the same directory.

  296. Lee / Jan 31 2010 3:58 am

    Hi,

    If someone could send me an example of…
    1. Form code for web page (insert in html web page)
    2. Form.php
    3. Recaptchalib.php

    I will be able to see where I am going wrong. Thanks!

    Send to: formcopy@rainbow-beach-holidays.com

  297. Keith N. / Jan 31 2010 1:42 pm

    Lee.

    Here ya go. I use the reCAPTCHA frequently, and given the questions I see here, I figure a complete demo might help shed some light.

    Download this ZIP file:
    http://www.spectrum-nashville.com/recaptcha_demo.zip

    Open it in a new, empty folder. Open the demo.php file and read through it. If you put your own Public Key and Private key in there and upload both files to your server, it should work (I verified it works on my server before I posted it).

    Good luc,.

  298. Lee / Feb 1 2010 6:10 pm

    Hi,
    I decided to try sitewizard’s code again.
    1. Form code
    2. Feedback.php
    3. Recaptchalib.php
    I simply added private keys and public keys. No other script.
    Well, it worked.
    The problem was that I was adding the 2 script clips above to feedback.php. They were already in the feedback.php to begin with.

    Thanks all for your help!

  299. Dan / Feb 4 2010 2:15 pm

    OK, I’ve messed with this for over a day now and while I got the code to show up, made both form and process pages .php, put in the code from a working example, I cannot get it to process.

    The code I have on the form page is (and it IS inside a form):

    My processed page has this code at the top:

    is_valid) {
    die (“The reCAPTCHA wasn’t entered correctly. Go back and try it again.” .
    “(reCAPTCHA said: ” . $resp->error . “)” .” back“);
    }

    rest of php process after this…

    I obviously have my correct keys in, just did not suply them here. What am I doing wrong?

  300. Dan / Feb 4 2010 2:25 pm

    well the code didnt post correctly, Ill try again here is the form page code:

    php start

    require_once(‘recaptchalib.php’);

    // Get a key from http://recaptcha.net/api/getkey
    $publickey = “mykey”;
    echo recaptcha_get_html($publickey);

    php end

    and the process page:

    php start

    require_once(‘recaptchalib.php’);
    $publickey = “mykey”;
    $privatekey = “mykey”;
    $resp = null;
    $error = null;
    if ($_POST[“recaptcha_response_field”]) {
    $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 . “)” .” back“);
    }
    rest of php process

  301. Dan / Feb 4 2010 2:59 pm

    I should note that everything APPEARS to function, but the check answer does not seem to matter whether you put in the wrong info, basically making the captcha useless

    • Keith N. / Feb 5 2010 12:12 am

      This could be very tough to troubleshoot in fragments. If you want, send a zip (or tar) of all the source files involved to me, and I’ll try to take a look.
      Send to help [at] spectrum-nashville.com.
      No promises, but maybe a fresh set of eyes will be the ticket.

      • Dan / Feb 5 2010 3:13 pm

        Thanks Keith, a little tweeking and it works now. I did have to remove it from the table in order to be more browser friendly also.

        • Keith / Feb 5 2010 6:00 pm

          Glad to hear it Dan. For anyone who comes along later and views this post, I figured I’d post the basics of our discovery here:

          We determined that the code line reading (see Dan’s code posted earlier):
          if($_POST[“recaptcha_response_field”]) {
          was a big part of the problem. It always evaluated as false, and it had no “else” section to die() if the condition failed.

          I suggested taking this conditional statement (and the braces for it) completely out of the code, since it is sort of a redundant test anyway.

          If one insists on keeping that line, though, I recommend using the isset() PHP function:
          if(isset($_POST[“recaptcha_response_field”])) {

          and remember to add an ‘else’ block to give an error message and die() whenever the $_POST variable is not set.

  302. Pook / Feb 4 2010 4:52 pm

    Dan, I’m having the same problem. Everything shows up all nice, but you could put anything in there and it is still accepting it.

  303. Pook / Feb 5 2010 3:21 pm

    Keith, may I also indulge you to look at mine, too?
    I’m having problems with my contact.php file that exists in the language/english folder.

    • Keith / Feb 5 2010 6:09 pm

      If you are having the same problem as Dan, then first I’d recommend looking at the Reply I just posted to Dan on this blog.
      I outlined in general terms how we solved his issue, and it may solve your problem as well.
      If it doesn’t, then let me know and we’ll see about taking a look.
      One particular nugget of wisdom we got out of testing with Dan: be sure to test with both IE and FF before you commit that your code doesn’t (or does) work. Our initial fix for Dan worked for me (with IE) but failed for him (Firefox). Be warned….
      Best luck!

  304. Dante / Feb 9 2010 10:07 am

    I am having the same issue; the form will process regardless of what I type into the text field. I will attempt to use your demo shortly after writing this.

    The question I have is; what if the Captcha is simply too wide to fit into the space allotted for my form? I only have about 200 pixels to work with and the Captcha seems to be about twice that…is there a way to make it appear narrower?

    You can see the small area I have for my form at hhrlaw.com

    ~Dante

  305. sunshine / Feb 14 2010 6:40 pm

    I have a bit of a problem.

    I have been using ReCAPTCHA for about 2 years now, but I’m trying to implement this on another page and it’s giving me problems.

    My form is in a folder as such:

    /website/test/contact-us.php

    My thank you page is as:

    /website/test/thank-you.php

    My captcha is as this:

    /websites/test/captcha/recaptchalib.php

    I have another recaptchalib.php residing here:

    /captcha/recaptchalib.php

    It seems I can get the captcha to show in /website/test/contact-us.php with this:

    require_once(“captcha/recaptchalib.php”);

    But the error it spits out on the /website/test/thank-you.php page is this:

    The reCAPTCHA wasn’t entered correctly. Go back and try it again.(reCAPTCHA said: )

    That’s bad enough.

    But I can get the form to work by putting the path to the recaptchalib.php like this:

    require_once(“/hsphere/local/home/accountname/server.com/captcha/recaptchalib.php”);

    but not like this:

    require_once(“/hsphere/local/home/accountname/server.com/website/test/captcha/recaptchalib.php”);

    What is going wrong?

  306. Kevin F. / Feb 15 2010 8:29 am

    I can’t get this to work 100%. I placed the initial code before the submit button and it works fine. The Captcha box shows up and works as it should…

    However, When I add the config. code to the top of the processing page I lose everything under it. When I add the config. code under the submit button, everything shows up above it, but my webpage’s footer & right container are lost.

    It seems like I am placing the config. code in the wrong spot.

    The only thing on my webpage is:
    “The reCAPTCHA wasn’t entered correctly. Go back and try it again.(reCAPTCHA said: incorrect-captcha-sol)”

    Any suggestions would be greatly appreciated!

    Kevin.

  307. Ged / Feb 18 2010 10:48 am

    Thank you for the excellent guide.
    Problems I hit of my own making were:
    1. “Invalid public key. Make sure you copy and pasted it correctly.” displayed where reCAPTCHA box should be.
    Couldn’t see any difference but deleted and repasted public key and all ok.
    2. All mail delivered regardless of input validity.
    I realised I hadn’t ftp’d the new version of my form process page so the validation check wasn’t there in the second page.
    3. Following valid input – “Warning: Cannot modify header information – headers already sent by (output ……………”.
    This was due to pasting the validation code in at the top but forgetting to remove the excess ?> and tags which now sat in the middle of my code.

    • Keith N. / Feb 18 2010 10:57 am

      Ged – I just want to say great job debugging the problems, but more important: THANKS for posting your issues AND SOLUTIONS to this blog for others to see.
      Sharing like this may help countless others “learn from your experience” and improve their chances of solving those little nit-picky problems that they encounter.

  308. Matt / Feb 18 2010 11:18 am

    I’m a web designer and very interested in using reCaptcha as spam prevention on many of my client’s websites.

    However, I am having trouble on my first installation. If you could help me I’d greatly appreciate it!

    As you know, in your (extremely helpful!) guide, if a visitor puts in a word incorrectly they get the new blank page with this:
    The reCAPTCHA wasn’t entered correctly. Please go back and try it again.(reCAPTCHA said: incorrect-captcha-sol)

    But on the reCaptcha website, I can see examples where, if the words aren’t entered correctly, the error message appears within the reCaptcha box and looking lovely and neat!

    Could you please help me to reconfigure this? I’m guessing I need to replace the ‘die’ instruction with something completely different but I’m a bit of a noob at PHP!

    • Keith N. / Feb 18 2010 11:27 am

      Matt:
      As a designer, you may be comfortable looking around in the HTML source of your designs and knowing your way around the “flow of your pages”.
      If so, you will probably benefit from my single-source method. The form, the reCaptcha, and the final result are all in one file, which allows the reCaptcha processing to happen within the regular flow of your web page design (inside a DIV or TABLE or whatever formatting you have in place) in a semi-plugin style.
      You may want to throw out this 2-file method shown on this blog and try my demo:
      http//:www.spectrum-nashville.com/recaptcha_demo.zip
      The documentation is inside the PHP file as comments….
      Good luck.

      • Keith N. / Feb 18 2010 11:28 am

        Sorry, I fat-fingered the URL. It should be:

        http://www.spectrum-nashville.com/recaptcha_demo.zip

        Better….

        • Matt / Mar 8 2010 6:06 am

          Hi Keith

          Sorry for taking so long to respond – I’ve been working on other aspects of the site (I hate forms and so have made it the last possible priority!).

          OK, so, yes, the Form uses header (in this case:

          header(“Location: http://www.mysite.co.uk/ecommerce/?id=28905“);

          fairly near the end of my form. My form used a separate PHP file for validating and processing the form too, which I have copied and pasted all the relevant code from into the single-page solution you generously supplied on your website. I believe that the form is ALMOST working (although kinda clunky-looking at present) but came back with varying errors depending on where I pasted my PHP code.

          Could you explain the proper format that I should be using? i.e. where should all my ‘processing PHP’ go, and where the header redirect should be in relation to that?

          …and also, for that matter, how much you’d charge for doing it for me 😉

          • Keith N. / Mar 8 2010 8:30 am

            It will probably be necessary to take a look at the php file to really answer completely, but here are a few thoughts first:

            The php header() function absolutely must be the very first “output” sent to the browser in order to work. So, when you mention the header() is “fairly near the end of my form”, I suspect that is a big part of the problem. It is also common practice to follow the header(“Location:…”) call with a php die() to keep from sending potentially confusing output to the visitor’s browser.

            For the header() to be used, you’d need to copy some of the demo code block starting with:

            if( $_POST[‘validate’] === ‘yes’ ) {

            up into the first <?php … ?> block and execute the header() redirection before ever hitting any “normal” HTML.

            That would also mean changing the error message “echo” to a line setting the message into some string variable

            ($myerrmsg=”…”)

            and echoing that back later in the HTML for your css-styled message. That’s because you don’t want to echo your message when the browser hasn’t even seen the <body> tag yet, among other considerations.

            Of course, just to be clear, this means that when a CAPTCHA validates, NONE of your HTML or code below the header()/die() calls will be executed or seen, since PHP will send the visitor skipping off to the new Location (seems fairly obvious, but maybe not).

            If that info puts you on track, then great. If not, it may be time for me to get a copy of your php and take a look.

            Looking is free, and my rates beyond that are real reasonable 😉

  309. matt / Feb 19 2010 7:32 am

    Thanks Keith I will look into that now.

    The page I need to add reCaptcha to though, then redirects to PayPal to take a payment… With your method wirk in this instance?

    Thanks again for the fast response!

    • Keith N. / Feb 20 2010 7:31 am

      That depends on whether you are redirecting to paypal using PHP header(), HTTP META REDIRECT, or PHP curl() features. So, the answer is a qualified yes-and-no.
      If you are using header() (a very likely scenario), you cannot send ANY other information (html, php echo, etc.) to the client before the header() call, so you would want the validation to be the very first thing in the page.
      Again, the method still works, but the if-then-else block would need to be moved up to the top of the page and handled a bit differently.
      Short answer: I’d need more information to answer you completely.

  310. ryan m. / Feb 22 2010 10:40 am

    Here’s my question: I’m placing the php in the header of my form page itself… here’s the current code before recaptcha:

    If I place the new php code for recapctha I get an error that i think has to do something with the header portion… Any insigt to this?

  311. ryan m. / Feb 22 2010 10:41 am

    crap… here’s the code:

    PHP START

    $error_msg = “”;
    if(isset($_POST[‘send’])){
    if(trim($_POST[‘name’])==”) $error_msg = “Name is required.”;
    elseif(trim($_POST[‘company’])==”) $error_msg = “Company is required.”;
    elseif(trim($_POST[‘title’])==”) $error_msg = “Title is required.”;
    elseif(trim($_POST[‘address’])==”) $error_msg = “Address is required.”;
    elseif(trim($_POST[‘city’])==”) $error_msg = “City is required.”;
    elseif(trim($_POST[‘state’])==”) $error_msg = “State is required.”;
    elseif(trim($_POST[‘zip’])==”) $error_msg = “Zip is required.”;
    elseif(trim($_POST[’email’])==”) $error_msg = “E-Mail is required.”;
    elseif(!isset($_POST[‘agree’])) $error_msg = “You must agree to terms by checking box.”;

    if($error_msg == “”){
    $msg = “”;
    $msg .= “Name: “.$_POST[‘name’];
    $msg .= “\n\nCompany: “.$_POST[‘company’];
    $msg .= “\n\nTitle: “.$_POST[‘title’];
    $msg .= “\n\nAddress: “.$_POST[‘address’];
    $msg .= “\n\nCity: “.$_POST[‘city’];
    $msg .= “\n\nState: “.$_POST[‘state’];
    $msg .= “\n\nZip: “.$_POST[‘zip’];
    $msg .= “\n\nEmail: “.$_POST[’email’];
    $msg .= “\n\nFax: “.$_POST[‘fax’];
    $msg .= “\n\nAgree to terms “.$_POST[‘agree’];
    mail(“ryan@envycreative.com”, “Webinar Registration”, $msg);
    header(‘Location: registration-complete.php?name=’.$_POST[‘name’].’&email=’.$_POST[’email’].’&pref=’.$_POST[‘class_pref’]);
    }

    }

    PHP END

    • Keith N. / Feb 22 2010 2:51 pm

      If all this php is the VERY FIRST THING in your php file, you should be OK. If there is ANYTHING, including white-space before it, the header() call will trigger an error message.

      Your post says this code is “in the header” … if that means between the tags, that is TOO LATE for the header() call to work.

      If it is truly at the TOP of the code, then you should be able to put something like the code below right before your if($error_msg==””) line:
      ========
      $response = recaptcha_check_answer(
      ‘your private key goes here’,
      $_SERVER[‘REMOTE_ADDR’],
      $_POST[‘recaptcha_challenge_field’],
      $_POST[‘recaptcha_response_field’]
      );
      if( ! $response->is_valid ) {
      $error_msg = $response->error;
      }
      ========

      That would put the reCAPTCHA error message in your $error_msg variable and trigger whatever error display mechanism you have later in your page (and prevent the mail() send and header() from happening, as it should)….

      • Keith N. / Feb 22 2010 2:54 pm

        update to the second paragraph in my previous reply. It should say if the PHP code is “between the <head> and </head> tags”, that is TOO LATE”.

        The blog software killed my head/head tags when I posted before.

  312. Deyan / Feb 23 2010 2:56 am

    Did anybody really know, why sometimes even the code is correct it says that the code is incorrect. Not always but sometimes from 10 attempts – 10 errors:)

    • Keith N. / Mar 1 2010 1:47 am

      I know for certain that you only have to get one word “right” to validate correctly. That is an expected behavior with reCAPTCHA.

      But, I have also seen cases where a “close match” seemed to validate even though I hadn’t put in exactly the right word. I don’t know why that happens or what the parameters are, though.

      Anybody else have any ideas?

  313. Kathie Meier / Feb 24 2010 5:05 pm

    Working on getting this added to our site –

    Finally got everything in the right place (I think) but it appears that responses are going through for failed entries and that all responses have recaptcha text on them –

    an intentional failure (for testing) generates a page with this message – The reCAPTCHA wasn’t entered correctly. Go back and try it again.(reCAPTCHA said: incorrect-captcha-sol) but apparently still let’s the form submission through (it is emailed to us)

    • Keith N. / Feb 24 2010 5:14 pm

      Come back to the inko9nito blog page where you posted and use your browser search to find this exact text:

      Dan – 02.04.10 at 2:59 pm

      Then read through the discussion Dan and I had. There’s a basic flaw in the if/then/else structure of the demo that may be causing your problem. That would be my first attempt at a fix, anyway.

      Good luck!

  314. Kathie Meier / Feb 24 2010 10:06 pm

    Got the false result fixed – thanks – any ideas on why we get text like this in the body of each message

    recaptcha_challenge_field: 02JO4kWYPRVG9QWkeCbqKJIf-iBpaDqhuzWMVpj8tp1e30IPSFfgkG2PjHZG2wQa_2bQWJ-H6Fp0h3S2mneYJu_Iy9QXYX5Q3vYd8vwgPgiRuGgG-xEInxnpHy9wx2sU-e78AhaHTvG-ttDoh4G0F3tSohRd1gMHYiC83gm15wSm7EeuiDz8Gzw6eG5zxp1G6ckiYe5YaNCd9s2EOMFB-0Uu1UlaTcGyJtiyrb0rkH3qBfRmT8EgTb8gmXjMA3u4vQxSlzPsEonRRvw3vCwzEy5nJt6n8B
    recaptcha_response_field: removal perhaps

  315. Keith N. / Feb 24 2010 11:11 pm

    You are echoing the 2 reCAPTCHA post fields into your message:
    $_POST[“recaptcha_challenge_field”]
    and
    $_POST[“recaptcha_response_field”]

    They are the source of the text you showed. Unless you find that data interesting, there is no need to capture it into your email message.

  316. Kathie Meier / Feb 25 2010 10:48 am

    Sorry I’m still having problems – if I remove those 2 lines I get an error

    This is what I have
    is_valid) {
    die (“The reCAPTCHA wasn’t entered correctly. Go back and try it again.” .
    “(reCAPTCHA said: ” . $resp->error . “)”);
    }
    ?>

    If I delete
    $_POST[“recaptcha_challenge_field”],
    $_POST[“recaptcha_response_field”]);

    then I get the following message on submission of the form

    Parse error: syntax error, unexpected T_IF in /home/speak18/public_html/kmpreview/join.php on line 32

    After taking the two lines out Line 32 reads:
    if (!$resp->is_valid) {

    Thanks so much for your help Keith – your fast responses have been very much appreciated.

    Kathie

    • Keith N. / Feb 25 2010 11:27 am

      Glad to help (or try, at least)….

      You will want to restore those lines around line 32 to the way they were before you removed the two POST variables. They are required in that particular section of code, because they are sent off for validation.

      The messy stuff showing up in your email messages occurs later in the code, where the message body is being built and sent. I’m not sure what code you have there, but it’ll be referencing either $_POST or $_REQUEST variables (look for the mail() command and then trace the code immediately preceding that).

  317. Kathie Meier / Feb 25 2010 6:39 pm

    So sorry – still having problems – if I fool with this script we no longer see who is subscribing – is this the part that is showing the recaptcha text lines? Many thanks – Kathie

    This is the PHP below the recaptcha –

    • Keith N. / Feb 25 2010 7:41 pm

      Your php code didn’t make the journey into the post above. It’s tough to troubleshoot something like this in bits-n-pieces, too.

      If you want, send your 2 php files to me offline:
      Email to: help [at] spectrum-nashville.com

      Maybe I can take a quick look and locate the problem.

  318. accesinterzis / Feb 26 2010 9:35 am

    Good job there…

  319. Alan Brind / Mar 2 2010 9:57 am

    Vera,

    Excellent job…I put in all the code and keys and it worked first time. But, the strip box function you suggested elongates the captcha field and overflows the right hand side column on my site, so I just went back to their original ugly red box. I’ll figure something out.

    Regards,
    Alan

  320. keith draper / Mar 2 2010 10:45 am

    Hello

    I have a contact page which is HTML and uses a CGI script for the from actions /cgi/gdform.cgi because i web host with Go Daddy and this is what they recommended. So can I use PHP or what is I need to do? By the way, you write very clear and logically. Thanks

    Keith Draper

    • Keith N. / Mar 3 2010 8:17 am

      I just saw a post below yours that listed a gdform.php file provided by GoDaddy.

      My guess is you’ll want to go find that file and use it instead of CGI if you want to add the reCAPTCHA stuff.

  321. Kathy Farrell / Mar 2 2010 10:01 pm

    Hello- I have a quoteform.html; gdform.php (a form file from Godaddy) and now the new recaptchalib.php. In which file do I add the public php code? And in which file do I add the private php code? Thanks for your HELP!!!

    • Keith N. / Mar 3 2010 8:15 am

      Public key and related code goes wherever you actually want the CAPTCHA image to show up (inside your form).

      the Private key and related code goes wherever your form sends the data.

      My guess in your case:

      public: quoteform.html
      private: gdform.php

      Those are just guesses. It’s hard to determine what is in the files from where I sit, based solely on their names.

      You’ll have to change quoteform.html to quoteform.php for this to work, in any case.

      Last, but not least, don’t edit anything inside the recaptchalib.php file.

  322. Kathy Farrell / Mar 3 2010 8:35 am

    Thanks for your reply Keith-

    1. the gdform.html has the code below in it. Do I add the new private php code above (or below) this within new tags or do I add it somewhere within the existing php code. Wasn’t sure if I can add more script to an exisitng php page

    2. Once I change the html page to a php. page will that effect the navigation throughout the site? Will I need to update the links?

    <?php
    $request_method = $_SERVER["REQUEST_METHOD"];
    if($request_method == "GET"){
    $query_vars = $_GET;
    } elseif ($request_method == "POST"){
    $query_vars = $_POST;
    }
    reset($query_vars);
    $t = date("U");

    $file = $_SERVER['DOCUMENT_ROOT'] . "/../data/gdform_" . $t;
    $fp = fopen($file,"w");
    while (list ($key, $val) = each ($query_vars)) {
    fputs($fp,"\n”);
    fputs($fp,”$val\n”);
    fputs($fp,”\n”);
    if ($key == “redirect”) { $landing_page = $val;}
    }
    fclose($fp);
    if ($landing_page != “”){
    header(“Location: http://“.$_SERVER[“HTTP_HOST”].”/$landing_page”);
    } else {
    header(“Location: http://“.$_SERVER[“HTTP_HOST”].”/”);
    }

    ?>

    • Keith N. / Mar 3 2010 9:34 am

      The code you have posted is the “Receiving End” for the data. Your private key and associated code should go here, at the beginning. Think of the private key & code as the lock on the gate. If the CAPTCHA validates, the code below it will run. If the CAPTCHA fails, the code below it will not run….

      You can either add the code in within new <?php … ?> tags, or you can just pull the “code” parts out and put them in immediately following the existing <?php markup that already exists. Either way is fine.

      The answer to question 2 is “YES”. Anywhere you have links on your site which point to the HTML file, you will have to change them to point to the PHP file instead.

  323. Kathy Farrell / Mar 3 2010 10:05 am

    I believe I got!
    Thanks for you quick response.
    You made my day!

    • Keith N. / Mar 3 2010 11:00 am

      Glad I could help. Congratulations and good luck with it!

  324. Richard B / Mar 3 2010 11:51 am

    I have an issue like Ryan M did back on the 22nd. My form and processing are all on the same contactus.php page.
    I have the Captcha showing, and I *think* processing a bit (no errors occur), it’s just that whether I enter the captcha or not, the email is not sent. Here’s part of the code:
    Form start area:

    <form name="form1" method="post" action="” title”Get more information”>

    Then the captcha itself is just before the submit button:

    Finally, after the submit, the php form processing continues, checking that a name and email was entered – this is also where I’ve put the “second” part of the captcha processing:

    is_valid) {
    $error = $resp->error;
    }

    and then finally the form data is sent via email. Like I said, it does not show an error when submit is clicked, whether or not the captcha is entered, but it also does not send the email.

    Thanks…

    • Richard B / Mar 3 2010 11:54 am

      I have an issue like Ryan M did back on the 22nd. My form and processing are all on the same contactus.php page.
      I have the Captcha showing, and I *think* processing a bit (no errors occur), it’s just that whether I enter the captcha or not, the email is not sent. Here’s part of the code:
      Form start area:

      PHP OPEN TAG
      if ($_SERVER[‘REQUEST_METHOD’] != ‘POST’){
      $me = $_SERVER[‘PHP_SELF’];
      session_register(“SESSION”);
      PHP CLOSE TAG
      <form name="form1" method="post" action="” title”Get more information”>

      Then the captcha itself is just before the submit button:

      PHP OPEN TAG
      require_once(‘recaptchalib.php’);
      $publickey = “…”;
      echo recaptcha_get_html($publickey);
      PHP CLOSE TAG

      Finally, after the submit, the php form processing continues, checking that a name and email was entered – this is also where I’ve put the “second” part of the captcha processing:

      FORM CLOSE TAG
      PHP OPEN TAG
      } else {
      error_reporting(0);
      //array to hold errors
      $errors = array();
      …more error checking…
      if (!$_POST[’email’])
      $errors[] = “eMail is required”;
      //CAPTCHA HERE
      $privatekey = “…”;
      $resp = null;
      $error = null;
      $resp = recaptcha_check_answer ($privatekey,
      SERVER[“REMOTE_ADDR”],
      $_POST[“recaptcha_challenge_field”],
      $_POST[“recaptcha_response_field”]);
      if ($resp->is_valid) {
      $error = $resp->error;
      }

      and then finally the form data is sent via email. Like I said, it does not show an error when submit is clicked, whether or not the captcha is entered, but it also does not send the email.

      Thanks…

      • Keith N. / Mar 3 2010 4:13 pm

        I’m not sure if the error is real, or just an artifact of copy/paste into the blog software, but your very last if() block says:

        if ($resp->is_valid) {
        $error = $resp->error;
        }

        That translates to “if the captcha response is VALID, then save an error message”.

        If you later decide whether to send email based on $error being empty, you won’t ever send an email.

        This should probably read:
        if ([bold]![/bold] $resp->is_valid) {
        $error = $resp->error;
        }

        The exclamation point would change it to “if … is NOT VALID, then error=…”.

        • Keith N. / Mar 3 2010 4:15 pm

          Ignore the “[bold]” and “[/bold]”.

          Apparently wordpress isn’t configured to handle BBcode markups for BOLD. Oh well.

          It should just read:
          if (! $resp->is_valid) {
          $error = $resp->error;
          }

  325. Jeff / Mar 4 2010 9:53 pm

    For those that still might be having trouble with godaddy’s gdform.php file, I noticed that the recaptcha code must be enclosed within its own set of PHP tags to get it to work properly:

    is_valid) {
    die (“The reCAPTCHA wasn’t entered correctly. Go back and try it again.” .
    “(reCAPTCHA said: ” . $resp->error . “)”);
    }
    ?>
    <?PHP
    $request_method = $_SERVER["REQUEST_METHOD"];
    if($request_method == "GET"){
    $query_vars = $_GET;
    } elseif ($request_method == "POST"){
    $query_vars = $_POST;
    }
    reset($query_vars);
    $t = date("U");

    $file = $_SERVER['DOCUMENT_ROOT'] . "/../data/gdform_" . $t;
    $fp = fopen($file,"w");
    while (list ($key, $val) = each ($query_vars)) {
    fputs($fp,"\n”);
    fputs($fp,”$val\n”);
    fputs($fp,”\n”);
    if ($key == “redirect”) { $landing_page = $val;}
    }
    fclose($fp);
    if ($landing_page != “”){
    header(“Location: http://“.$_SERVER[“HTTP_HOST”].”/$landing_page”);
    } else {
    header(“Location: http://“.$_SERVER[“HTTP_HOST”].”/”);
    }
    ?>

  326. Alan / Mar 6 2010 9:16 am

    I am totaly lost as to how to do this, The below is my (register.php) file where i guess i need to put this. Does anyone want to hold my hand and show me how to do this?

    include(“include/config.php”);
    include(“include/functions/import.php”);

    $pagetitle = “$lang[14]”;
    STemplate::assign(‘pagetitle’,$pagetitle);

    $redirect = base64_decode($_REQUEST[‘redirect’]);
    $redirect = escape($redirect);

    if ($_SESSION[‘USERID’] != “” && $redirect != “”)
    {
    header(“Location:$redirect”);exit;
    }

    STemplate::assign(‘bdays’,listdays(0));
    STemplate::assign(‘bmonths’,listmonths(0));
    STemplate::assign(‘byears’,listyears(0));

    if($_REQUEST[‘register’]!=””)
    {
    $username = cleanit($_REQUEST[‘username’]);
    $username = str_replace(“(“, “”, $username);
    $username = str_replace(“)”, “”, $username);
    STemplate::assign(‘username’,$username);
    $password = stripslashes(strip_tags($_REQUEST[‘password1’]));
    STemplate::assign(‘pw’,$password);
    $confirmpassword = stripslashes(strip_tags($_REQUEST[‘confirmpassword’]));
    STemplate::assign(‘pw2’,$confirmpassword);
    $imagecode = stripslashes($_REQUEST[‘imagecode’]);
    $email = stripslashes(strip_tags($_REQUEST[’email’]));
    STemplate::assign(’email’,$email);
    $day1 = intval($_REQUEST[‘day’]);
    $month1 = intval($_REQUEST[‘month’]);
    $year1 = intval($_REQUEST[‘year’]);
    STemplate::assign(‘bdays’,listdays($day1));
    STemplate::assign(‘bmonths’,listmonths($month1));
    STemplate::assign(‘byears’,listyears($year1));

    if($username == “”)
    {
    $err1 = “$lang[15]”;
    STemplate::assign(‘err1’,$err1);
    }
    elseif(!verify_email_username($username))
    {
    $error = “$lang[19]”;
    }

    if ($password == “”)
    {
    $err2 = “$lang[20]”;
    STemplate::assign(‘err2’,$err2);
    }

    if ($confirmpassword == “”)
    {
    $err3 = “$lang[23]”;
    STemplate::assign(‘err3’,$err3);
    }

    if ($password != “” && $confirmpassword != “” && $password != $confirmpassword)
    {
    $err2 = “$lang[22]”;
    STemplate::assign(‘err2’,$err2);
    $err3 = “$lang[21]”;
    STemplate::assign(‘err3’,$err3);
    }

    if ($email == “”)
    {
    $err4 = “$lang[26]”;
    STemplate::assign(‘err4’,$err4);
    }
    elseif(!verify_valid_email($email))
    {
    $err4 = “$lang[24]”;
    STemplate::assign(‘err4’,$err4);
    }
    elseif (!verify_email_unique($email))
    {
    $err4 = “$lang[25]”;
    STemplate::assign(‘err4’,$err4);
    }

    if ($imagecode == “”)
    {
    $err5 = “$lang[28]”;
    STemplate::assign(‘err5’,$err5);
    }
    elseif($imagecode != $_SESSION[imagecode])
    {
    if ($config[‘enable_captcha’] != “0”)
    {
    $err5 = “$lang[27]”;
    STemplate::assign(‘err5’,$err5);
    }
    }

    if ($day1 <= "0")
    {
    $err6 = "$lang[32]";
    STemplate::assign('err6',$err6);
    }
    if ($month1 <= "0")
    {
    $err7 = "$lang[33]";
    STemplate::assign('err7',$err7);
    }
    if ($year1 execute($query);
    $userid = mysql_insert_id();

    if($userid != “” && is_numeric($userid) && $userid > 0)
    {
    $query=”SELECT USERID,email,username,verified from members WHERE USERID='”.mysql_real_escape_string($userid).”‘”;
    $result=$conn->execute($query);

    $SUSERID = $result->fields[‘USERID’];
    $SEMAIL = $result->fields[’email’];
    $SUSERNAME = $result->fields[‘username’];
    $SVERIFIED = $result->fields[‘verified’];
    SESSION_REGISTER(“USERID”);
    $_SESSION[USERID]=$SUSERID;
    SESSION_REGISTER(“EMAIL”);
    $_SESSION[EMAIL]=$SEMAIL;
    SESSION_REGISTER(“USERNAME”);
    $_SESSION[USERNAME]=$SUSERNAME;
    SESSION_REGISTER(“VERIFIED”);
    $_SESSION[VERIFIED]=$SVERIFIED;

    // Generate Verify Code Begin
    $verifycode = generateCode(5).time();
    $query = “INSERT INTO members_verifycode SET USERID='”.mysql_real_escape_string($SUSERID).”‘, code=’$verifycode'”;
    $conn->execute($query);
    if(mysql_affected_rows()>=1)
    {
    $proceedtoemail = true;
    }
    else
    {
    $proceedtoemail = false;
    }
    // Generate Verify Code End

    // Send Welcome E-Mail Begin
    if ($proceedtoemail)
    {
    STemplate::assign(‘verifycode’,$verifycode);
    $sendto = $SEMAIL;
    $sendername = $config[‘site_name’];
    STemplate::assign(‘sendername’,$sendername);
    $from = $config[‘site_email’];
    $query = “SELECT * FROM sendmail WHERE EID=’welcomeemail'”;
    $executequery = $conn->execute($query);
    $subject = $lang[‘275’].” “.$sendername;
    $sendmailtemplate = $executequery->fields[‘template’];
    $sendmailbody=STemplate::fetch($sendmailtemplate);
    mailme($sendto,$sendername,$from,$subject,$sendmailbody,$bcc=””);

    $esub = $lang[‘275’].” “.$config[‘short_name’];
    $emsg = $lang[‘338’];
    $query = “INSERT INTO messages_inbox SET MSGTO='”.mysql_real_escape_string($SUSERID).”‘, MSGFROM=’0’, subject='”.mysql_real_escape_string($esub).”‘, message='”.mysql_real_escape_string($emsg).”‘, time='”.time().”‘”;
    $conn->execute($query);
    }
    // Send Welcome E-Mail End

    if($redirect == “”)
    {
    header(“Location:$config[baseurl]/invite_friends.php”);exit;
    }
    else
    {
    header(“Location:$redirect”);exit;
    }
    }
    }
    }
    STemplate::display(‘header.tpl’);
    STemplate::display(‘register.tpl’);
    STemplate::display(‘footer.tpl’);
    ?>

  327. Thomas Vogt / Mar 6 2010 9:57 am

    Hi,

    first of all thank you for this great captcha. I was searching for a long time but I didn’t find a solution which I could understand.

    Now my form works, but together with the captcha I get an error message:

    Warning: Cannot modify header information – headers already sent by (output started at /mounted-storage/…/mywebsite.com/sendmail.php:14) in /mounted-storage/…/mywebsite.com/sendmail.php on line 82

    Here is the responsible part of the sendmail-php:

    header( “Location: http://www.mywebsite.com/thankyou.html” );
    }

    it belongs to the part:


    else {
    mail( “info@mywebsite.com”, “Message”,
    $message, “From: $email” );
    header( “Location: http://www.mywebsite.com/thankyou.html” );
    }

    Is there a chance to help me?

    BR
    Tom

  328. primadonna / Mar 6 2010 7:42 pm

    lanselotus afigenius

  329. Samdp / Mar 9 2010 9:14 am

    Excellent,

    I just used the Javascript theme option on one of the sites.

  330. www.webdetale.com / Mar 17 2010 5:32 pm

    Hello-
    I added the captcha and thought it was working but it is not.
    It shows up but when I hit the submit I get this warning:

    Warning: Cannot modify header information – headers already sent by (output started at /home/content/g/r/a/grandisleties/html/gdform.php:19) in /home/content/g/r/a/grandisleties/html/gdform.php on line 39

    Any ideas why this is happening?
    http://www.grandisleties.com/quoteform.php

    Thank you

    • Keith N. / Mar 17 2010 9:03 pm

      This error means you have the header() statement in a place in your code AFTER some other output has already been sent to the browser. It could be white-space or other html (impossible to say without seeing the code up to and including line 39).

      Look to see what is in the file prior to the header() statement.

  331. www.webdetale.com / Mar 18 2010 8:46 am

    Hi-
    Confused. Am I looking on the gdform.php where I placed the private key code or am I looking on the quoteform.php where I placed the captcha?

    You can see the code on the quoteform.php by going to http://www.grandisleties.com/quoteform.php

    Thank you

  332. Keith N. / Mar 18 2010 9:23 am

    I don’t intend to sound condescending here, but:

    (1) The error message says “gdform.php” — that’s where the error is.

    (2) No, folks cannot see your PHP code by browsing the URL. The web server (actually the PHP processor embedded in the web server) interprets the PHP into HTML for the browser. The browser never sees the PHP. The only way anyone can review your code is if you email it to them or copy/paste and post it.

    I did browse to your form, and it looks to be functioning fine. My guess is you should leave the code in quoteform.php alone completely. The problem is definitely in the gdform.php file.

    Good luck.

  333. cullenassociates / Mar 18 2010 9:57 am

    Appreciate you taking the time.
    At the risk of looking stupid;
    Here is the code that is beneath the captcha code.

    <?php
    $request_method = $_SERVER["REQUEST_METHOD"];
    if($request_method == "GET"){
    $query_vars = $_GET;
    } elseif ($request_method == "POST"){
    $query_vars = $_POST;
    }
    reset($query_vars);
    $t = date("U");

    $file = $_SERVER['DOCUMENT_ROOT'] . "/../data/gdform_" . $t;
    $fp = fopen($file,"w");
    while (list ($key, $val) = each ($query_vars)) {
    fputs($fp,"\n”);
    fputs($fp,”$val\n”);
    fputs($fp,”\n”);
    if ($key == “redirect”) { $landing_page = $val;}
    }
    fclose($fp);
    if ($landing_page != “”){
    header(“Location: http://“.$_SERVER[“HTTP_HOST”].”/$landing_page”);
    } else {
    header(“Location: http://“.$_SERVER[“HTTP_HOST”].”/”);
    }

    ?>

    Line 39 specifically is:
    header(“Location: http://“.$_SERVER[“HTTP_HOST”].”/$landing_page”);

    Thank you

  334. Kathy Farrell / Mar 18 2010 10:15 am

    Hello again-

    I installed the captcha code above the godaddy form code in its own php tags.

    I called Godaddy about line 39.

    They said their form code is working but that the captcha code is causing the disruption and they cannot help me with solving the issue.

  335. Keith N. / Mar 18 2010 10:26 am

    First, don’t worry about looking stupid … I believe in the rule “there are no stupid questions”. As I said above, I seriously didn’t want to sound condescending or belittling. My intent was to educate and hopefully help nudge you toward a solution.

    Posting the code was a good idea. Looking at the code vs. the error message, I have a couple pointers that may help.

    Around line 19 you have this if/else block:
    if ($landing_page != “”){
    header(“Location: http://”.$_SERVER%5B“HTTP_HOST”].”/$landing_page”);
    } else {
    header(“Location: http://”.$_SERVER%5B“HTTP_HOST”].”/”);
    }

    First thing I notice is that you’re going to issue a header(“Location:”) call either way. Technically, you should probably always follow the header() with die(), because you really can’t do much else without risking the error you’re getting. Think of header(“Location:…”) as saying “send the browser somewhere else right now”.

    Second, you may be having problems because of characters that look similar to humans but which are not equal to the computer. I can’t tell if it’s just because of the copy/paste into this blog, but it looks like a lot of your double-quotes are “real, human, open- and close-quotes” (they angle left/right to indicate open/close). This is not the same thing the PHP interpreter expects for a double-quote, and it could be confusing things.

    The first thing I would do is go through all this code and replace anything that looks like a double-quote with this character: ” (that is the Shift of the apostrophe on the far right side of home row). Don’t use a word processor (like MS Word, for example) to do the editing — use something purely text-based (like Notepad in Windows, for instance).

    Word processors are notorious for trying to be “smart” and replace the straight-up double quote with “real” quotes.

    Give that a try and let us know how it goes….

  336. Keith N. / Mar 18 2010 10:30 am

    The double-quote issue may be imaginary — when I reviewed my post, the blog software converted all my double-quotes to smart quotes too…. So maybe you’ll be OK there. I’d still check to be sure.

    I’ll try to use an HTML trick to represent the only valid double-quote for PHP. It is: "

    If all your source code actually is using the " character, then the problem probably goes back to that if/else block at line 19.

  337. Olivecrazy / Mar 28 2010 5:39 pm

    Help! I just posted something to the ReCaptcha group, and its not working…

    I’ve tested everything, and it only works when I take the location of
    the php mailhandler out.

    So, when I used the “hello world” example – http://recaptcha.net/plugins/php/

    It only worked when I left the action blank.

    So, obviously I know its something wrong in the PHP, but I can’t
    figure it out.

    Please help!!! 🙂

    This is what I have:

    ?php

    require_once(‘/recaptchalib.php’);
    $privatekey = “MYPRIVATEKEYISHERE”;
    $resp = recaptcha_check_answer ($privatekey,
    $_SERVER[“MYIPADDRESSISHERE”],
    $_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 . “)”);

    }

    if ( !isset($_SERVER[‘SPI’])) {
    die();

    }

    if (!isset($_SERVER[‘DOCUMENT_ROOT’])) {
    echo(“CRITICAL: we seem to be running outside of the norm.\n”);
    header(“Location: http://“.$_SERVER[“HTTP_HOST”].”/”);
    die(“CRITICAL: Document root unavailable.\n”);
    }

    ….

    • Keith N. / Mar 29 2010 9:10 am

      First, the line reading:
      $_SERVER[“MYIPADDRESSISHERE”],
      is wrong. That should read:
      $_SERVER[‘REMOTE_ADDR’],

      Second, I have no idea what $_SERVER[‘SPI’] may be, but I’d probably comment that entire if() block out and try it. Make it look like this:
      /*
      if ( !isset($_SERVER[‘SPI’])) {
      die();

      }
      */

      Give those changes a try and post back what happens….

  338. Dondon Gabas / Mar 29 2010 2:30 am

    Hi!

    Nice post. Unfortunately doesn’t work for me.

    I really don’t know why..

  339. Dondon Gabas / Mar 29 2010 2:36 am

    I got this error message when i save it

    Warning: require_once(recaptchalib.php) [function.require-once]: failed to open stream: No such file or directory in /home2/seaexpl2/public_html/administrator/components/com_chronocontact/admin.chronocontact.php(2736) : eval()’d code on line 208

    Fatal error: require_once() [function.require]: Failed opening required ‘recaptchalib.php’ (include_path=’.:/usr/lib/php:/usr/local/lib/php’) in /home2/seaexpl2/public_html/administrator/components/com_chronocontact/admin.chronocontact.php(2736) : eval()’d code on line 208

    • Keith N. / Mar 29 2010 9:00 am

      This one means the PHP processor can’t find the recaptchalib.php file. It needs to be downloaded from the reCAPTCHA web site and uploaded to your web server in the same directory as your form.

      In this case, that looks like it would be
      /administrator/components/com_chronocontact/

  340. Dondon Gabas / Mar 29 2010 2:39 am

    and also this one…

    Fatal error: Cannot redeclare class ReCaptchaResponse in /home2/seaexpl2/public_html/components/com_chronocontact/recaptchalib.php on line 137

  341. Ed / Mar 30 2010 4:27 pm

    Warning: require_once – solution:

    make sure you upload your recaptchalib.php file to your web server as well.

    make sure it is in the same path as your form files. If it is outside of the same folder add ../ like so ../recaptchalib.php

    hope this helps

  342. Leena / Apr 3 2010 2:12 am

    Hi, I have the captcha installed and everything is working. but the captach is always “invalid”. I have tried with explorer and firefox.

    Please advice on how i can come around this.

    Thanks

  343. Keith N. / Apr 3 2010 9:05 am

    If you’ve browsed through all the posts on this blog and tried the various suggestions throughout (I know, it has gotten long, but there are some good posts sprinkled in ), then it is probably time to post some code and comments to see if someone can see what’s going wrong.

    Good luck.

  344. leena / Apr 4 2010 6:34 am

    Kethi, i have done as stated in solutions here, up to my extent.

    (php code start)
    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 . “)”);
    }
    (php code end)

    here is one code as u have given. Can u please explain to me here how to remove

    $_POST[“recaptcha_response_field”]);

    and the add “else”. Please provide me the code here.

    here is in details on what kind of script I am working on (http://www.zimmertech.com/tutorials/php/25/comment-form-script-tutorial.php). Please have a look at it and tell me how i should go through this error.

    Thanks a lot for the reply

    • Keith N. / Apr 4 2010 9:17 pm

      Leena:

      I downloaded the Zimmerman tutorial file and added the reCAPTCHA into on my server. What I discovered is that there is an error on testpage.php that may make you think the reCAPTCHA is failing when it is not!

      Check your database to see if your test comments have been posting to be sure. If so, the error is in testpage.php:

      submitComments(“1″,”$PHP_SELF”);

      should really read:

      submitComments(“1″,”testpage.php”);

      I realized that after the reCAPTCHA validated on my copy, the redirect tried to send the user back through validation a second time, but without the necessary data fields.

      Just in case that was NOT the problem, though, I posted ZIP file with my changes to the Zimmerman tutorial. You can get my zip file with the working code here:

      http://spectrum-nashville.com/reCAPTCHA/zimmerman/zimmerman_recaptcha.zip

      You can see it working live on my web server by browsing to here:
      http://spectrum-nashville.com/reCAPTCHA/zimmerman/testpage.php

      Hope that puts you on the right track. I may post a comment to Zimmerman as well asking about the testpage.php error….

      • Keith N. / Apr 4 2010 9:23 pm

        I failed to mention, the ZIP only contains these files:
        * tespage.php
        * submitcomment.php
        * inc_rate.php

        Be sure not to unzip these over any work you’ve done, unless you’re sure you mean to do so.

        Also, in the submitcomment.php and inc_rate.php, you can Search for the phrase “RECAPTCHA” within the text to find the code changes I made.

  345. Leena / Apr 5 2010 1:07 am

    Keith N., Your my hero. Thanks alot for helping me and all others here. will keep on coming to learn from you often.

    regards

    • Keith N. / Apr 5 2010 9:08 am

      I guess that means it worked 😉
      Glad to help.

  346. Carl / Apr 7 2010 8:39 pm

    I wonder if you could help me out. After a good amount of experimentation, I finally found the process file that my server uses, and have pasted the code and am getting the reCaptcha to appear correctly. However, if I leave the reCaptcha box blank, or enter the wrong text, the form is still submitted.

    Have you encountered this issue, and can you suggest a workaround? Please let me know if there is any other information you need.

    Thanks!
    Carl

    • Keith N. / Apr 7 2010 9:13 pm

      Just to be clear, you do realize that you need to paste TWO pieces of code (into 2 separate areas), right?
      The first part makes the reCAPTCHA box appear, and belongs in the file with the form, but the second part is the true validation.
      The validation part will likely reside in a different file. Without the validation part, it doesn’t matter what you put into the reCAPTCHA box.
      That’s just one possibility, though. You’ll need to supply a lot more detail before anyone can have any chance to really help (files, code, etc.).
      Good luck!

      • Carl / Apr 7 2010 10:08 pm

        Keith,

        Thanks for the quick reply. I am somewhat of a coding novice, particularly as it applies to PHP, but think I can get myself around, with a little help. Here is the code I have pasted into the form (note that I’ve not included the entire form, just the code at the end before the submit button):

         

         
        Please click the Submit button only once.
        If you are not taken to the confirmation screen, please check the form for errors.
        Click the Submit button again once the errors have been corrected.

        Here is the code I submitted into what I think is the form processing file (I’ve included the entire file code here):

        is_valid) {
        die (“The reCAPTCHA wasn’t entered correctly. Go back and try it again.” .
        “(reCAPTCHA said: ” . $resp->error . “)”);
        }
        ?>
        “Error”,
        2 => “Warning”,
        4 => “Parsing Error”,
        8 => “Notice”,
        16 => “Core Error”,
        32 => “Core Warning”,
        64 => “Compile Error”,
        128 => “Compile Warning”,
        256 => “User Error”,
        512 => “User Warning”,
        1024=> “User Notice”,
        2048=> “E_ALL”,
        2049=> “PHP5 E_STRICT”

        );
        $str = sprintf(“[%s]\n%s:\t%s\nFile:\t\t’%s’\nLine:\t\t%s\n\n”, date(‘d-m-Y H:i:s’),(isset($errortype[@$errno])?$errortype[@$errno]:(‘Unknown ‘.$errno)),@$errstr,@$errfile,@$errline);
        if (error_reporting() != 0) {
        @fwrite($f, $str);
        if (@$errno == 2 && isset($already_sent) && !$already_sent==true){
        $error = ”.”\n”;
        $error .= ‘An Warning Type error appeared. The error is logged into the log file.’.”\n”;
        $error .= ”.”\n”;
        $already_sent = true;
        echo $error;
        }
        }
        }
        if ($debug_to_file){
        $old_error_handler = set_error_handler(“KT_ErrorHandler”);
        }

        class MySqlConnection
        {
        /*
        // The ‘var’ keyword is deprecated in PHP5 … we will define these variables at runtime.
        var $isOpen;
        var $hostname;
        var $database;
        var $username;
        var $password;
        var $timeout;
        var $connectionId;
        var $error;
        */
        function MySqlConnection($ConnectionString, $Timeout, $Host, $DB, $UID, $Pwd)
        {
        $this->isOpen = false;
        $this->timeout = $Timeout;
        $this->error = ”;

        if( $Host ) {
        $this->hostname = $Host;
        }
        elseif( preg_match(“/host=([^;]+);/”, $ConnectionString, $ret) ) {
        $this->hostname = $ret[1];
        }

        if( $DB ) {
        $this->database = $DB;
        }
        elseif( preg_match(“/db=([^;]+);/”, $ConnectionString, $ret) ) {
        $this->database = $ret[1];
        }

        if( $UID ) {
        $this->username = $UID;
        }
        elseif( preg_match(“/uid=([^;]+);/”, $ConnectionString, $ret) ) {
        $this->username = $ret[1];
        }

        if( $Pwd ) {
        $this->password = $Pwd;
        }
        elseif( preg_match(“/pwd=([^;]+);/”, $ConnectionString, $ret) ) {
        $this->password = $ret[1];
        }
        }

        function Open()
        {
        $this->connectionId = mysql_connect($this->hostname, $this->username, $this->password);
        if (isset($this->connectionId) && $this->connectionId && is_resource($this->connectionId))
        {
        $this->isOpen = ($this->database == “”) ? true : mysql_select_db($this->database, $this->connectionId);
        }
        else
        {
        $this->isOpen = false;
        }
        }

        function TestOpen()
        {
        return ($this->isOpen) ? ” : $this->HandleException();
        }

        function Close()
        {
        if (is_resource($this->connectionId) && $this->isOpen)
        {
        if (mysql_close($this->connectionId))
        {
        $this->isOpen = false;
        unset($this->connectionId);
        }
        }
        }

        function GetTables($table_name = ”)
        {
        $xmlOutput = “”;
        if ($this->isOpen && isset($this->connectionId) && is_resource($this->connectionId)){
        // 1. mysql_list_tables and mysql_tablename are deprecated in PHP5
        // 2. For backward compatibility GetTables don’t have any parameters
        if ($table_name === ”){
        $table_name = @$_POST[‘Database’];
        }
        //added backtick for handling reserved words and special characters
        //http://dev.mysql.com/doc/refman/5.0/en/legal-names.html
        $sql = ‘ SHOW TABLES FROM ‘ . $this->ensureTicks($table_name) ;
        $results = mysql_query($sql, $this->connectionId) or $this->HandleException();

        $xmlOutput = “”;

        // Columns are referenced by index, so Schema and
        // Catalog must be specified even though they are not supported

        $xmlOutput .= ‘TABLE_CATALOG’; // column 0 (zero-based)
        $xmlOutput .= ‘TABLE_SCHEMA’; // column 1
        $xmlOutput .= ‘TABLE_NAME’; // column 2

        $xmlOutput .= “”;

        if (is_resource($results) && mysql_num_rows($results) > 0){
        while ($row = mysql_fetch_array($results)){
        $xmlOutput .= ” . $row[0]. ”;
        }
        }
        $xmlOutput .= “”;

        }
        return $xmlOutput;
        }

        function GetViews()
        {
        // not supported
        return “”;
        }

        function GetProcedures()
        {
        // not supported
        return “”;
        }

        function GetColumnsOfTable($TableName)
        {
        $xmlOutput = “”;
        //added backtick for handling reserved words and special characters
        //http://dev.mysql.com/doc/refman/5.0/en/legal-names.html
        $query = “DESCRIBE “.$this->ensureTicks($TableName);
        $result = mysql_query($query) or $this->HandleException();

        if ($result)
        {
        $xmlOutput = “”;

        // Columns are referenced by index, so Schema and
        // Catalog must be specified even though they are not supported
        $xmlOutput .= “TABLE_CATALOG”; // column 0 (zero-based)
        $xmlOutput .= “TABLE_SCHEMA”; // column 1
        $xmlOutput .= “TABLE_NAME”; // column 2
        $xmlOutput .= “COLUMN_NAME”;
        $xmlOutput .= “DATA_TYPE”;
        $xmlOutput .= “IS_NULLABLE”;
        $xmlOutput .= “COLUMN_SIZE”;

        $xmlOutput .= “”;

        // The fields returned from DESCRIBE are: Field, Type, Null, Key, Default, Extra
        while ($row = mysql_fetch_array($result, MYSQL_ASSOC))
        {
        $xmlOutput .= “”;

        // Separate type from size. Format is: type(size)
        if (preg_match(“/(.*)\((.*)\)/”, $row[“Type”], $ret))
        {
        $type = $ret[1];
        $size = $ret[2];
        }
        else
        {
        $type = $row[“Type”];
        $size = “”;
        }

        // MySQL sets nullable to “YES” or “”, so we need to set “NO”
        $null = $row[“Null”];
        if ($null == “”)
        $null = “NO”;

        $xmlOutput .= “” . $row[“Field”] . “”;
        $xmlOutput .= “” . $type . “”;
        $xmlOutput .= “” . $null . “”;
        $xmlOutput .= “” . $size . “”;
        }
        mysql_free_result($result);

        $xmlOutput .= “”;
        }

        return $xmlOutput;
        }

        function GetParametersOfProcedure($ProcedureName, $SchemaName, $CatalogName)
        {
        // not supported on MySQL
        return ”;
        }

        function ExecuteSQL($aStatement, $MaxRows)
        {
        if ( get_magic_quotes_gpc() )
        {
        $aStatement = stripslashes( $aStatement ) ;
        }

        $xmlOutput = “”;

        $result = mysql_query($aStatement) or $this->HandleException();

        if (isset($result) && is_resource($result))
        {
        $xmlOutput = “”;

        $fieldCount = mysql_num_fields($result);
        for ($i=0; $i < $fieldCount; $i++)
        {
        $meta = mysql_fetch_field($result);
        if ($meta)
        {
        $xmlOutput .= 'type;
        $xmlOutput .= ‘” max_length=”‘ . $meta->max_length;
        $xmlOutput .= ‘” table=”‘ . $meta->table;
        $xmlOutput .= ‘” not_null=”‘ . $meta->not_null;
        $xmlOutput .= ‘” numeric=”‘ . $meta->numeric;
        $xmlOutput .= ‘” unsigned=”‘ . $meta->unsigned;
        $xmlOutput .= ‘” zerofill=”‘ . $meta->zerofill;
        $xmlOutput .= ‘” primary_key=”‘ . $meta->primary_key;
        $xmlOutput .= ‘” multiple_key=”‘. $meta->multiple_key;
        $xmlOutput .= ‘” unique_key=”‘ . $meta->unique_key;
        $xmlOutput .= ‘”>’ . $meta->name;
        $xmlOutput .= ”;
        }
        }

        $xmlOutput .= “”;
        $row = mysql_fetch_assoc($result);

        for ($i=0; $row && ($i < $MaxRows); $i++)
        {
        $xmlOutput .= "”;

        foreach ($row as $key => $value)
        {
        $xmlOutput .= “”;
        $xmlOutput .= htmlspecialchars($value);
        $xmlOutput .= “”;
        }

        $xmlOutput .= “”;
        $row = mysql_fetch_assoc($result);
        }

        mysql_free_result($result);

        $xmlOutput .= “”;
        }

        return $xmlOutput;
        }

        function GetProviderTypes()
        {
        return ”;
        }

        function ExecuteSP($aProcStatement, $TimeOut, $Parameters)
        {
        return ”;
        }

        function ReturnsResultSet($ProcedureName)
        {
        return ”;
        }

        function SupportsProcedure()
        {
        return ”;
        }

        /*
        * HandleException added by InterAKT for ease in database translation answer
        */
        function HandleException()
        {
        global $debug_to_file, $f;
        $this->error = create_error(‘ MySQL Error#: ‘. ((int)mysql_errno()) . “\n\n”.mysql_error());
        log_messages($this->error);
        die($this->error.”);
        }

        function ensureTicks($inputSQL)
        {
        $outSQL = $inputSQL;
        //added backtick for handling reserved words and special characters
        //http://dev.mysql.com/doc/refman/5.0/en/legal-names.html

        //only add ticks if not already there
        $oLength = strlen($outSQL);
        $bHasTick = false;
        if (($oLength > 0) && (($outSQL[0] == “`”) && ($outSQL[$oLength-1] == “`”)))
        {
        $bHasTick = true;
        }
        if ($bHasTick == false)
        {
        $outSQL = “`”.$outSQL.”`”;
        }
        return $outSQL;
        }

        function GetDatabaseList()
        {
        $xmlOutput = ‘NAME’;

        if (isset($this->connectionId) && is_resource($this->connectionId)){
        $dbList = mysql_list_dbs($this->connectionId);

        while ($row = mysql_fetch_object($dbList))
        {
        $xmlOutput .= ” . $row->Database . ”;
        }
        }else{
        $this->error = CONN_NOT_OPEN_GET_DB_LIST;
        return $this->error;
        }
        $xmlOutput .= ”;

        return $xmlOutput;
        }

        function GetPrimaryKeysOfTable($TableName)
        {
        $xmlOutput = ”;
        //added backtick for handling reserved words and special characters
        //http://dev.mysql.com/doc/refman/5.0/en/legal-names.html
        $query = “DESCRIBE “.$this->ensureTicks($TableName);
        $result = mysql_query($query) or $this->HandleException();

        if ($result)
        {
        $xmlOutput = ”;

        // Columns are referenced by index, so Schema and
        // Catalog must be specified even though they are not supported
        $xmlOutput .= ‘TABLE_CATALOG’; // column 0 (zero-based)
        $xmlOutput .= ‘TABLE_SCHEMA’; // column 1
        $xmlOutput .= ‘TABLE_NAME’; // column 2
        $xmlOutput .= ‘COLUMN_NAME’;
        $xmlOutput .= ‘DATA_TYPE’;
        $xmlOutput .= ‘IS_NULLABLE’;
        $xmlOutput .= ‘COLUMN_SIZE’;

        $xmlOutput .= ”;

        // The fields returned from DESCRIBE are: Field, Type, Null, Key, Default, Extra
        while ($row = mysql_fetch_array($result, MYSQL_ASSOC))
        {
        if (strtoupper($row[‘Key’]) == ‘PRI’){
        $xmlOutput .= ”;

        // Separate type from size. Format is: type(size)
        if (preg_match(“/(.*)\((.*)\)/”, $row[‘Type’], $ret))
        {
        $type = $ret[1];
        $size = $ret[2];
        }
        else
        {
        $type = $row[‘Type’];
        $size = ”;
        }

        // MySQL sets nullable to “YES” or “”, so we need to set “NO”
        $null = $row[‘Null’];
        if ($null == ”)
        $null = ‘NO’;

        $xmlOutput .= ” . $row[‘Field’] . ”;
        $xmlOutput .= ” . $type . ”;
        $xmlOutput .= ” . $null . ”;
        $xmlOutput .= ” . $size . ”;
        }
        }
        mysql_free_result($result);

        $xmlOutput .= ”;
        }
        return $xmlOutput;
        }

        } // class MySqlConnection
        ?>

        It was not until I pasted the validation code into this particular file that the captcha would even show up in the first place.

        Does this help at all…?

        Carl

        • Carl / Apr 7 2010 10:10 pm

          That didn’t seem to work…

          Here is the form code:

           

           
          Please click the Submit button only once.
          If you are not taken to the confirmation screen, please check the form for errors.
          Click the Submit button again once the errors have been corrected.

          • Carl / Apr 7 2010 10:10 pm

            OK, it doesn’t seem to be pasting the code. Is there a way I can upload the file?

          • Keith N. / Apr 8 2010 7:44 pm

            The blog doesn’t allow upload, but if you want to email the code to me, you can try that.
            Send a ZIP file of the program code to me at my company’s Help address:
            help[at]spectrum-nashville.com

          • Keith N. / Apr 14 2010 10:32 am

            Carl: I never saw a file at that email address. Hopefully that means you were able to get everything working.
            Best.

  347. Dalena / Apr 14 2010 11:47 am

    I added this program because I was getting slammed with spam account requests. I followed the instructions and get “The reCAPTCHA wasn’t entered correctly. Go back and try it again.(reCAPTCHA said: incorrect-captcha-sol)”
    and no Submit button. I see I am not the only user with this issue; however, I found no solution listed.

    http://gone2texas.us/Genrecords/newacctform.php

    Thanks for your assistance.

    • Keith N. / Apr 14 2010 1:41 pm

      At the risk of sounding contrary, there are actually several good solutions to the various problems posted here. It takes a lot of reading to isolate exactly which solution you need.

      I browsed to the gone2texas.us form link that you posted, and I see the reCAPTCHA error message appearing immediately on the form screen. That would imply to me that you have your validation code in the wrong place.

      The reCAPTCHA get_html stuff goes with the form code. Based on this tutorial, the code for VALIDATION goes in a separate page (the page that actually processes the form data).

      I’d recommend that you take another look through this tutorial AND all the comments posted to see if you can isolate the specific problem you are experiencing. Then if you still need help, post back with some details on what you’ve done so someone can take a shot at helping you out.

      Good luck.

  348. Javier / Apr 14 2010 5:20 pm

    i installed a recaptcha, it works almost perfect except for one flaw. lets say the code to solve is “HOUSE BLUE” and someone types in “HOUS BLU” it will still go through. is it because it’s close enough to being solved that it accepts it? is there a setting that needs to be adjusted in the recapchalib.php file that requires it to be solved 100% accurate?

    • Keith N. / Apr 14 2010 9:09 pm

      This text is from the reCAPTCHA Wiki and addresses your question:

      reCAPTCHA consists of two words: a verification word, to which the reCAPTCHA server knows the answer and a read word which comes from an old book. The read word is not graded (since the server is using human guesses to figure out the answer). As such, this word can be entered incorrectly, and the CAPTCHA will still be valid. Each read word is sent to multiple people, so incorrect solutions will not affect the output of reCAPTCHA.

      On the verification word, reCAPTCHA intentionally allows an “off by one” error depending on how much we trust the user giving the solution. This increases the user experience without impacting security. reCAPTCHA engineers monitor this functionality for abuse.

  349. Simple Things / Apr 15 2010 8:37 pm

    I already tried this on my contact page. And it does not work to save the information to MySQL.

  350. ERiK / Apr 16 2010 11:18 am

    nothing shows up in g chrome, ff, or ie 8?
    i’ve got a contact page php page a process page php and recaptchalib in php. here’s the code for contact

    Feedback Form

    var RecaptchaOptions = {
    theme: 'clean'
    };
    </script

    Feedback Form

    Name:
    Email:
    Message:


    this page looks good in preview in Dreamweaver mx.
    my process will come next if this page is really messed and it works after your expert eyes examine it. thank you if you can help. i’m doing this coding as a volunteer for a church so i’m not working for pay “just” learning experience.

  351. ERiK / Apr 16 2010 11:26 am

    not all my code showed up:
    i’ll try again:

      $name = $_REQUEST[['name'];
      $email = $_REQUEST['email'] ;
      $message = $_REQUEST['message'] ;
    
       if (!isset($_REQUEST['email'])) {
        header( "Location: http://www.templeisraelottawa.ca/feedback.html" );
      }
      elseif (empty($name) || empty($email) || empty($message)) {
        
    	header( "Expires: Mon, 20 Dec 2011 01:00:00 GMT" );
        header( "Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT" );
        header( "Cache-Control: no-cache, must-revalidate" );
        header( "Pragma: no-cache" ); 
    	
    
        <html>
        <head>
    	<title>Feedback Form</title></head>
        <script type= "text/javascript">
    var RecaptchaOptions = {
    theme: 'clean'
    };
    </script
    	 </head>
        <body>
    
        
        
        <h1>Feedback Form</h1>
    
        <p>
        <form method="post" action="sendmail.php">
        Name: <input type="text" name="name" /><br>
    	Email: <input type="text" name="email" /><br />
        Message:<br><textarea name="message" rows="15" cols="40">
        </textarea><br />
    	<?php
    require_once('recaptchalib.php');
    $publickey = "6LeOggwAAAAAAxPrQ-n9NrK72i5F3Sk8KJrULz"; // you got this from the signup page
    echo recaptcha_get_html($publickey);
    <html>
        <input type="submit" />
        </form>
        </p>
    </html>
        </body>
        </html>
    
  352. Keith N. / Apr 16 2010 12:33 pm

    It is sometimes difficult to tell if the code suffers from translation in posting to the blog, or if a real error exists; nonetheless, I’ll do my best to point out a few things that jump at me:

    1. I hope you actually have <?php and ?> tags around all the PHP, including at line 01 (open) and line 13 (close). If so, they were lost in the posted code….

    2. The elseif block at line 8 doesn’t seem to have a closing brace. It looks like it should go before Line 13. This could be your biggest problem.

    3. Lines 38 and 42 show an extra block of <html> and </html> tags.

    4. Line 17 has an extra </head> tag at the end.

    5. Line 37 should end with a ?> (PHP close) tag.

    6. The header(“Location: …”) looks messed up in the post above, but I think that is an artifact of the blog translating the link.

    Check those items first, especially number 2, and let us know how it goes!

    Good luck.

    • ERiK / Apr 16 2010 1:40 pm

      thank you very much. i’ve been working on this almost all day. i need a break; so will get to it tomorrow as i need to go out tonight. i tried the site wizard but it says on the feedback.html page that the key is incorrect. i know it is above in my post but i copied it from the recaptcha page and it still says it’s incorrect??
      thank you for your response

    • ERiK / Apr 18 2010 6:45 am

      thanks Keith it works now. but tell me is there a way to add a drop down box with names that if the user chooses one an email will be sent to the selected name? i do need help i’m a newbie and doing this as a volunteer.

      • Keith N. / Apr 18 2010 9:23 am

        A dropdown is known as a SELECT in HTML. The dropdown goes in your form, and it looks like this:

        <select name="pick_a_recipient" id="pick_a_recipient">
           <option value="sales@disney.com" selected="selected">Sales Desk</option>
           <option value="mickey@disney.com">Mickey</option>
           <option value="goofy@disney.com">Goofy</option>
           <option value="minnie@disney.com">Minnie</option>
        </select>
        

        Then, when you process the form, you just see which option they selected by checking for:
        $_POST[‘pick_a_recipient’]
        Use that value in your mail() call to route the message to the correct person. As with all form variables and POST variables, whatever you use as “name” on the select is the same value you look for in the $_POST.

        • ERiK / Apr 19 2010 9:56 am

          thank you. i now have the form worked out ..except .. there’s no generic ”Saes dep. with an email.. i just want the select box to say Choose one.? i can’t fiure out how to do that. if you could help it would be great. i have 3 people sender can select from. thank you.

          • Keith N. / Apr 19 2010 11:04 am

            The content of the <select> is up to you.
            In generic form it would look like this:

            <select name="pick_a_recipient" id="contact_choice">
              <option value="email 1">Name 1</option>
              <option value="email 2">Name 2</option>
              <option value="email 3">Name 3</option>
            </select>
            

            Put as many — or as few — “option” tags as you want. Then substitute in the values for the email addresses and names.

            Just like other HTML tags, every <option> ends with a matching </option> tag.

            If this is above your experience level, you should look at this link:
            http://www.w3schools.com/TAGS/tag_select.asp

            and bookmark it. The w3schools.com site is a great training reference for the various HTML tags you should know.

            The example code above may look clearer if you use the “copy this code” feature of the blog and look at it in another text editor, too. The extra “line wrapping” for this tiny column can make the code confusing to interpret visually.

            Good luck.

          • ERiK / Apr 19 2010 12:42 pm

            that code gives the same results as i had. i guess my description of what i am trying to do and perhaps it’s not possible is as follows:
            when page opens the viewer will see: Select contact person: there will be a drop down box; as it is now the first name is showing and the other two/more are only presented when clicking the down arrow of the box. i would like to have instead of the first name of a recipient the text choose a recipient. then next in the process form file would i insert $_post = goofy and so on?

          • ERiK / Apr 19 2010 1:03 pm

            thank you for your patience and help. one more thing i would rather not have spam bots or ner doers sends from the source so do i use a “hidden” type input in the html?
            thanks.
            another thing: should i name all email choices and code $_post= email1 etc.? it’s not to clear on w3 site. at least for me.

          • ERiK / Apr 20 2010 7:20 pm

            thank you. i took the day off from trying to figure this out and came back to it this evening; reread the posts (yours) and inserted code $_post [add_a_recipient] and it now works. thank you very much. gee i’m dumb.

          • Keith N. / Apr 20 2010 8:26 pm

            So glad you had success.

            Don’t beat yourself up, though; sometimes taking a break from the code is the best thing to do.

            It helps to see things again with “fresh eyes”, ya know?
            Take care.

  353. Yahoo custom store development / Apr 17 2010 11:22 am

    regarding spiritman’s post above – my experience was the same. as long as i entered ANYTHING in the captcha field, my form would get through.

    as you suggested, i went back and grabbed the code that captcha provided at signup rather than the code in this tutorial and it immediately began working properly.

    thanks for offering so much help.
    you’re the best!

  354. doh! / Apr 18 2010 9:18 am

    Hi there!

    I don’t understand one thing:
    After typing in the correct words of re-captcha, i want to forward to a new site.
    But i don’t understand how to make this real.

    Then i tried this:

    if(!$resp->is_valid) {
    header(“location:this_site_should_to_see.php”);
    die();
    }

    I think that have to worked BUT listen to this shiAt:
    header already sent!

    So i was tried to the possibility to delete “location:” and change from “header” to include.
    Ok that works for this BUT i dont want to include because my site will be destroyed through this.

    => Can anyone tell me PLEASE, how i can load a complete new page as like i clicking a link in a normal homepage?
    PLEASE!

    Thank you very much!!!

    • Keith N. / Apr 18 2010 10:13 am

      The header(“Location:…”) function absolutely HAS to be placed BEFORE anything else is sent as output. That means before any HTML (even just the <html> tag) or anything else.

      If CAN follow PHP code, but there still can be no “whitespace” before it either.

      If this is placed at the very top of your source file:

      <?php
      	$resp = recaptcha_check_answer( API_PRIVATE_KEY,
      										   	$_SERVER['REMOTE_ADDR'],
      											$_POST['recaptcha_challenge_field'],
      											$_POST['recaptcha_response_field']
      											);
      	if(!$resp->is_valid) {
      		header(“location:this_site_should_to_see.php”);
      		die();
      	}
      ?>
      

      it should work fine. But be aware, even blank lines or spaces that exist ABOVE or BEFORE the &lt?php tag will give you the “header already sent” error.

      If this doesn’t work out for you, you could also consider using an HTML meta refresh to make the redirect happen. Somewhere in the HEAD section of your html, you put something like this:

      <meta http-equiv="REFRESH" content="0;url=http://www.the-domain-you-want-to-redirect-to.com"> 
      

      See this link for a brief description:
      http://www.internetofficer.com/seo/html-redirect/

      Or just google for “html redirect” or “html refresh”.

      In the past, there have been some browsers that have refused to perform the redirect based on HTML refresh, so you should usually include a “real/normal” link in your page somewhere too, that say “If you don’t get redirected in X seconds, click here to continue…”.

      Hope that helps.

    • Keith N. / Apr 18 2010 10:16 am

      I just realized an error in my example of header() code. I think you want to continue to the new site if the reCAPTCHA is VALID, so the if() would look like THIS:

      <?php
      	$resp = recaptcha_check_answer( API_PRIVATE_KEY,
      										   	$_SERVER['REMOTE_ADDR'],
      											$_POST['recaptcha_challenge_field'],
      											$_POST['recaptcha_response_field']
      											);
      	if($resp->is_valid) {
      		header(“location:this_site_should_to_see.php”);
      		die();
      	}
      ?>
      
      

      The only difference is the “!” has been removed from the if( $resp->is_valid)….

      • realmasterblaster / Apr 18 2010 10:56 am

        I think i have to refuse, because i don’t understand the procedure of re-captcha.

        But meanwhile i have understood what does it means with the ” ! &resp” and without the “!”.
        Ok but that was just copied from your example far above for that posting and in my form/sourcecode it’s all correct.
        Sorry about that!!!
        I didn’t realized that what the “!” means.

        The nifty thing for me is to understand WHY i can’t forward to a new site and WHAT i have to fill in the forwarded/new php so that a user can not display the forwarded page as stand alone.
        If you understand what i mean? (sry for my very bad english, i’m from north germany!)

        The example you was given to me is not understandable for me because, i repeat, i fully don’t(!) understand the method of re-captche to work for me and my thinking about ” i want to redirect to the new site”. *lol*

        I mean, i’ve tried your method but it doesn’t work.
        I put your code in the very first line of the captcha page and i’ll getting a new problem:
        Parse error: syntax error, unexpected ‘:’ in /www/contact_captcha.php on line 8
        (thats the one with the “location” part)

        But hey: There must exists an other possibility to load a new page with php or not?
        I mean without include. Include per se works but it destroys my site. -.-”
        Maybe i have to take anything with get or url? I don’t know so much ’bout php. -.-”

        And i don’t know it. It’s sooo depressing for me. :.-(

        Because of that i didn’t realized the other solution and i didn’t knew anything about that how i can save the forwarded site, so that no other user can see this “as stand alone” site. You know? 😦

        4short again: It doesn’t work and i hope you can help me further.
        You are a specialist for sure and if you can’t help me, no other can help me. (i guess ^_~ )

        What do you think about my crappy thinking?

        Best greetings from northern outskirts of germany. 😉

        • Keith N. / Apr 18 2010 11:18 am

          Well, hello to Germany from a little town near Nashville, Tennessee, USA!

          I’m still not sure I completely understand the question, and I’ll be away for a while now, but here are some basic thoughts:

          1. If you have a page and you just want to force all browser visits away from that page, you can use the PHP header() with no other parts. Example, to force all visitors to a page to redirect to google:

          <?php header("Location: http://www.google.com");
          

          It still has to be the very FIRST thing in your php page file. No blank lines before it, no spaces, tabs, etc. before it either.

          2. The Line 8 error you saw is probably because you copied my exact code, but I didn’t actually format the header() call correctly. It should look something like this:

          header("Location: http://www.google.com");
          

          (again just using google.com as the site you want to go to for example).

          Unfortunately, I must go at the moment. Let me know if this helps at all — I will check back later.

          • doh! / Apr 19 2010 5:38 am

            Ahh Nashville, Tennessee …
            I Looove Whiskey. *rofl*

            But back to topic. ^.^

            Well, i think we are both talking past each other. (i hope this sentence was right?)

            Just imagine:
            I got 3 Sites!
            The first is the homepage (index.php) with a link to the contactform,
            called captcha.php!
            In this captcha.php is re-captcha implemented.

            So if i type in the captcha i wish to directed to the contactform, called contact.php!

            And that’s my/our problem!
            That doesn’t works!
            And i have no clue. -.-”

            I tried so much right now. Header here, header there….then a few other scripts, then i was looking about header on:
            http://php.net/manual/en/function.header.php
            …and…. uhm…ok

            Ok the header works. But if i load captcha.php (with modified header like you told me), the contactform is load immediatly without loading captcha.php.

            I’ll getting crazy right now. Believe in me. ^_^

            ~~~~~~~~~
            The other thing is, how can i protect the contact.php (or prevent) against the user?
            Yes i know what you mean with the redirect.
            But i mean, i don’t want that user can see the contact.php without typing in the re-captcha.
            You know what i mean?
            ~~~

            So i hope now, you know what i really mean.
            And i hope you can help me further again?

            Best Greetings from a real jackass. *rofl* 😉

          • doh! / Apr 19 2010 5:45 am

            !CORRECTIONS!
            I mean NOT:
            […]with a link to the contactform,
            called captcha.php![..]
            I mean:
            […]with a link to the captcha-site,
            called captcha.php![..]

            I’m really sorry for my bad mistake!

          • Keith N. / Apr 19 2010 11:36 am

            OK. I think I follow.

            1. The index.php just links to the action. When the link is clicked, the visitor should see the reCAPTCHA form …

            2. the reCAPTCHA form is in captcha.php and all it does is display the reCAPTCHA words to be typed in by visitor …

            3. the visitor completes the reCAPTCHA and is allowed to see the contents in contact.php page.

            Is that right? I’ll assume “yes” until I hear different. OK, so here’s what happens.

            1. index.php: nothing to do here; it just has link to captcha.php.

            2. captcha.php: show the visitor the reCAPTCHA, then go to contact.php to validate it (that’s the way the flow has to work to really protect contact.php correctly). The entire page might look like this:

            <html>
                <head>
                   <title>This is captcha.php</title>
                </head>
                <body>
                   <?php require_once('recaptchalib.php'); ?>
                   <form method="post" action="contact.php">
                       <?php echo recaptcha_get_html("YOUR PUBLIC KEY FROM RECAPTCHA.NET GOES HERE"); ?>
                       <br>
                       <input type="submit" value="Submit" />
                   </form>
                </body>
            </html>
            

            3. contact.php: validate the reCAPTCHA before allowing the contact form to show up at all. If no match, just error message shows up.

            <html>
                <head>
                   <title>This is contact.php</title>
                </head>
                <body>
                   <?php 
                   	// VALIDATE the reCAPTCHA HERE with error message if it
                    // does not validate. Then the visitor must use BACK button on 
                    // browser to go try again, but the Contact form will not
                    // be shown.
                   	require_once('recaptchalib.php'); 
            		$result = recaptcha_check_answer( "YOUR PRIVATE API KEY FROM RECAPTCHA.NET GOES HERE",
            										   	$_SERVER['REMOTE_ADDR'],
            											$_POST['recaptcha_challenge_field'],
            											$_POST['recaptcha_response_field']
            											);
            		
            		if( ! $result->is_valid ) {		
                    	// did not match, display this message to visitor and stop 
                    	die("You did not match the reCAPTCHA words. Please hit Back and try again!");
                    }
                    
                   ?>
                   
                   <!---
                   			YOUR ORIGINAL CONTACT FORM GOES RIGHT HERE...
                            (replaces this little example form).
                            It will show up if the reCAPTCHA validates,
                            but it will NOT show up if reCAPTCHA fails.
                   -->
                   <form>
                   	   Name: <input type="text" name="Name" /><br />
                       Email: <input type="text" name="Email" /><br />
                       Message: <input type="text" name="Message" /><br />
                       <input type="submit" value="Submit" />
                   </form>
                </body>
            </html>
            
            

            This example will work with you providing only the API KEY VALUES that you received when you registered with recaptcha.net.

            Also remember the recaptchalib.php file must exist on your web server in the same folder as all these files, or the “require_once” will fail with an error message.

            The one key concept you may have been missing: the reCAPTCHA validation part of the code MUST be physically in the php page that you want to protect; otherwise, someone could always go directly to the page and bypass the reCAPTCHA.

            Hopefully I didn’t miss anything. We’ll see 😉

            p.s.: I’ll say “hi” from you to Jack Daniels, just down the road from here!

  355. M / Apr 18 2010 9:18 pm

    i have the form but i am not recieving emails. otherwise it is ok. but i need to get the emails? i have a form index page and a process page. please advise. thanks.

    • Keith N. / Apr 18 2010 11:39 pm

      Not much I can tell from this information, except the problem is likely to be in your process page.

      I assume the process page attempts to validate the captcha, then creates an email and sends it?

      Here are some questions to answer:
      1. Do you see any error messages?
      2. Do you know your system allows PHP to send email?
      3. Which email function are you using?
      4. Does anything show up at all on screen when you submit your form? If so, then what?
      5. Do you want to post your code for review?

      Best.

  356. doh! / Apr 20 2010 5:15 am

    I GOT IT!!!
    THANK YOU Keith N.!!!

    Everything works fine and i understood now, how reCAPTCHA works!!!

    That’s so wonderful and i made it twice in german and english language.
    What else i can say? Just: Thank You sooo much!!!
    GrEaT!
    And best greetings to the good old “Jack”. 😉

    ~~~~~~~~~~~~~~~~~~~~~
    But something serious by the way:
    “In still mourning to the victims of the Knoxville Hospital”
    I followed it yesterday (19.april 2010) in german tv and i have to say that’s really rude and sad.
    ~~~~~~~~~~~~~~~~~~~~~

    • Keith N. / Apr 20 2010 6:51 am

      So glad to hear of your success!

      Thanks for your comments on Knoxville, too. We are also watching and very saddened.

      Best wishes,
      Keith

  357. TamDosya / Apr 22 2010 4:23 pm

    Thank you very much…

    Metin2 Multihack

  358. nate / Apr 25 2010 9:26 pm

    First of all, thanks for this, it got me up and running.

    I am wondering if anyone knows a way to bypass the extra functions of the recaptcha box in the tabindex? (audio, refresh)

    I am using a php installation and would love to be able to have these skipped when tabbing through the fields.

    thanks!

    • Keith N. / Apr 25 2010 9:39 pm

      I don’t know of a “quick” way to do this, but if you are pretty handy with HTML and JavaScript, you might could use the Custom Theming option to completely provide your own form for the reCAPTCHA.

      I’ve never tried this myself, but it is described on the reCAPTCHA site here:
      http://recaptcha.net/apidocs/captcha/client.html

      Once you surf to that page, use your browser’s Search/Find feature to seek out the text “Custom Theming” on the page.

      Hope that helps!

  359. phil j / Apr 26 2010 12:56 am

    I inserted the code into my own php form file and into my html website form which i changed the html to a php extension.

    Everything working fine except if i hit the submit but just below the recaptcha code and leave the recaptcha field blank it seems to process the form and completely bypass the recaptcha process?

  360. DaveB / Apr 26 2010 8:56 am

    Hi. Apologies in advance for being thick, but could someone clarify which lines should be removed as per the ‘Dan’ post further up? I got lost with references to braces I think….

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

    I’m also getting a problem whereby anything input will allow the form to be submitted, and am presuming this fix is a likely candidate to try first.

    • DaveB / Apr 26 2010 8:59 am

      Sorry, pasting appears to gone awry, try again without the php tag

      require_once(‘recaptchalib.php’);
      $privatekey = “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 . “)”);

      • Keith N. / Apr 26 2010 10:04 am

        Actually, the if() block we removed from Dan’s code isn’t shown in the code you pasted at all. You may have correctly removed it already, or it could exist outside of the scope of code pasted.

        The simplest form of code for the validation processing looks like this:

        <?php
          require_once('recaptchalib.php');
          $result = recaptcha_check_answer( 
              "your-private-key",
              $_SERVER['REMOTE_ADDR'],
              $_POST['recaptcha_challenge_field'],
              $_POST['recaptcha_response_field']
            );
        
          if( ! $result->is_valid ) {
            // did not match, display this message to visitor and stop
            die("You did not match the reCAPTCHA words. Please hit Back and try again!");
          }
        ?>
        

        Place that block first thing after your HTML <body> tag, and put your own API Private Key value in place of “your-private-key”, and it should work fine.

        You can fine-tune the error message in the die() function to your liking, of course.

        Then, any processing you want to do when the reCAPTCAH is valid, just put it after this little code block.

        An invalid CAPTCHA submission will issue the die() error message and quit, essentially pre-empting anything that follows it.

        Hope that helps.

        • DaveB / Apr 27 2010 2:26 am

          Thanks Keith. Some progress made with that, but still not there.
          What happens now is that the page immediately loads with just the text
          “You did not match the reCAPTCHA words. Please hit Back and try again!”
          and that’s before the actual forms page is accessed.
          The structure of the form is probably having an effect. It’s made up
          header.php which contains the tag
          index.php which contains the form stuff itself which renders in multiple pages.
          footer.php which contains the tag
          then a .js file which validates the submitted fields.
          I’ve also tried entering the code at the top of the index.php file, and the .js file. Neither of which work.

          • DaveB / Apr 27 2010 2:37 am

            Sorry again, tags 😦

            header.php which contains the body tag
            footer.php which contains the /body tag

          • Keith N. / Apr 27 2010 8:39 am

            I see. Yes, the tutorial described in this blog really applies to using reCAPTCHA when your form is rendered in a separate file than the processing code.

            For example, if you had:

            1. myform.php: show the form and reCAPTCHA, but with <form action=”myworker.php” method=”post” >

            2. myworker.php: this validates the form data ($_POST), checks the reCAPTCHA, and actually does whatever work is done (send email, write to database, etc.).

            If I understand correctly, you have (in essence) a single index.php that does both jobs, rendering the form one time, then validating and processing the data the second time.

            You would probably be better off to look at a single-file demo I put together a while back which is explicitly designed for this scenario.

            You can see the demo working at:
            http://www.spectrum-nashville.com/reCAPTCHA/demo.php

            You can download all the source code for the demo at:
            http://www.spectrum-nashville.com/reCAPTCHA/recaptcha_demo.zip

            This demo is heavily commented inside the PHP file to show how it works.

            Maybe it will help clear up any lingering problems you’re having.

  361. AlexX / Apr 29 2010 12:56 pm

    Hi..thanks for this captcha but i have some questions..I`m using phpbb3 and i want to add the captcha to the registration form, where to add the 2 codes from the top ? Both of them in the ucp_register.html ?

    Waiting for someone answer, thanks in advance

  362. Joe / May 4 2010 8:50 pm

    Thanks for the info, I have this working great for a site I am working on now. I did notice that it’s not accurate 100% of the time though. I can sometimes input only the first word and it will send the email. Other times not. Sometimes I can input only the second word and it will send as well and other times not. Very interesting….. It still requires the user to input the fields so it’s still a great addition to the site. Thanks for the tutorial.

  363. sadas / May 8 2010 11:33 pm

    sadda

  364. Jessica / May 11 2010 12:19 pm

    Hi Keith,

    I came across this blog post when searching for code on requiring the captcha to be filled out before the form when through. I’m very new at this and am learning every day with a project.

    But, here’s my situation. I have code on my site currently that shows a captcha (I only wanted numerical) form and generates a random number every time it’s refreshed. My problem is that I’m missing a key element of captcha, which is to have that field actually required. The code is kind of pieced together from me.

    Here is what is on the form to create the field:

    Retype Security Code:

    <– security code

    Then this is the code for the “Random Number” file:

    <?php
    function imgsecuregen($size = 6){

    $width = 11*$size;
    $height = 30;

    $string = "";
    for($i = 1; $i

    So my question is, can I pull some of your code/instructions from the re-captcha check answer function? Or will that not work because it’s for an image, and not numerical.

    Any help or guidance would be much appreciated.

    • Jessica / May 11 2010 12:25 pm

      well that didn’t copy well.

      <?php
      function imgsecuregen($size = 6){

      $width = 11*$size;
      $height = 30;

      $string = "";
      for($i = 1; $i

    • Keith N. / May 11 2010 1:16 pm

      To paste code into the blog where we can read it, you need to surround it with this tag:
      [code]
      … paste your code here …
      [/code]

      As I understand, though, you are randomly generating a number and asking the user to type it into a text-type input, right?

      I don’t think any of the code related to reCAPTCHA specifically will help, but you can still make it work.

      The trick is to communicate to your system what the random number should be, so that your verification code can work.

      I have this question: what is the action=”” for the form that has the numerical captcha element on it? Does it post back to itself, or post the data to a separate PHP file for processing?

      Wherever, the action takes the form data, THAT is where the verification must take place. The verification is just a matter of looking at what the user provided and comparing it to an expected value.

      Let me know the answer to that question and that I’m even in the ballpark here. I’ll help as much as I can, but I’ll need a bit more info.

      Good luck.

      • Jessica / May 11 2010 1:24 pm

        Hi Keith,

        Thanks for your quick response.

        Here is the code for the form action=”

        <link href="../css/prestigefinancial.css" rel="stylesheet" type="text/css">
        
        <script src="/js/jquery.js" type="text/javascript"></script>
        <script src="/js/jquery.maskedinput.js" type="text/javascript"></script>
        <script src="/includes/captcha/captcha.php" type="text/javascript"></script>
        <form action="" method="post">
            <br/>
            <input type="submit" name="submit" value="submit" />
            </form>
        <script>
        jQuery(function($){
        	$('#phone_home').mask('(999) 999-9999');
        	$('#phone_work').mask('(999) 999-9999');
        	$('#phone_mobile').mask('(999) 999-9999');
        });
        </script>
         
        <script src="http://prestigefinancialsolutions.com/includes/mootools-release-1.11.js"
            type="text/javascript" language="javascript">
        </script>
        
        <script src="http://prestigefinancialsolutions.com/includes/validators.js" type="text/javascript"
            language="javascript">
        </script>
        
        <form action="http://prestigefinancialsolutions.com/crm/index.php?entryPoint=WebToLeadCapture"
            name="WebToLeadForm" method="post" id="WebToLeadForm">
        

        for the line that is within the form calling the above file is:

        <?php
        function imgsecuregen($size = 6){
             
            $width = 11*$size;
            $height = 30;
             
            $string = "";
            for($i = 1; $i <= $size; $i++){
                $string .= rand (0,9)."";
            } // for
             
            $im = ImageCreate($width, $height);
            $bg = imagecolorallocate($im, 255, 255, 255);
            $black = imagecolorallocate($im, 0, 0, 0);
            $grey = imagecolorallocate($im, 170, 170, 170);
            imagerectangle($im,0, 0, $width-1, $height-1, $grey);   
            imagestring($im, 5, $size, 5, $string, $black);
            imagepng($im);
            imagedestroy($im);
        }
        
        imgsecuregen(10);
        
        ?>
        

        So, from what you are saying, I think I need to edit the “WebtoleadForm” is that correct?

        • Keith N. / May 11 2010 2:07 pm

          Hmmm. Truthfully, there are several questions the code brings to mind, but let’s start with basics:

          1. Lines 06-09 in the first code block seem to be a semi-empty form (nothing but a Submit button). Any idea why that would appear there?

          2. Line 26 in the first code block looks like it is the beginning of the real form, but the copy/paste probably cut it short (there aren’t inputs or an end tag).

          3. If Line 26 is the form in question, then yes, the action= points us toward the place for verification. It acutally points to /crm/index.php with a parameter of WebToLeadCapture. I don’t know what “crm” you are using, but that WebToLeadCapture will probably be the validation point.

          4. This is the real kicker: imgsecuregen() generates the picture code for you, but it doesn’t tell you what the code actually was. As the code stands, I don’t see any way you can validate the entry, since you don’t know what random number was in the string variable. Am I missing something there?

          Does that last question make sense to you? It’s OK for a random number to be in the picture, but you need to know what the number was if you want to verify that the user correctly matched the number, right?

          If I’m right on #4, then the first problem to solve is storing the random number somewhere for validation. After that, the second priority is to find where WebToLeadCapture takes us in the web site code….

          Thoughts at this point?

  365. Prasadi / May 12 2010 12:28 am

    thank u sooooooooooooooooooooooooooo much!!! ❤

  366. Gewinne / May 16 2010 7:58 am

    hi there
    i’m so pleased that i saw this website. that post was so nice. thanks again i bookmarked this website.
    are you planning to post similar posts?

  367. kesang / May 17 2010 4:09 pm

    thanks. it sure will keep those creeps away now.

  368. rexx009 / May 19 2010 6:28 pm

    IF YOU ARE USING A TABLE FOR YOUR FORM . . .
    You need to place the form tags completely outside of the table tags, or reCAPTCHA will just keep saying the answers you typed are wrong. Drove me CRAZY!!!

  369. Nikhil / May 24 2010 9:30 pm

    I want to set up a comment section very similar to this one on my website.

    I have very basic knowledge of web development, languages etc. I usually just edit templates and make static web pages. this is the first time i am working with databases and php etc.

    All my knowledge is from googling anything and everything and through forums like this one.

    And ofcourse the reason i am posting here is because I want it to be verified by reCAPTCHA to avoid spam

    • Keith N. / May 25 2010 11:44 am

      There is a how-to for creating a comments section like this that is very good at this location:
      http://www.zimmertech.com/tutorials/php/25/comment-form-script-tutorial.php

      I took that tutorial and just edited certain code to add reCAPTCHA to it.

      You should probably read the Zimmertech tutorial first, then go to my edited version for the reCAPTCHA stuff at:

      http://spectrum-nashville.com/reCAPTCHA/zimmertech/

      Good luck.

    • Keith N. / May 25 2010 11:55 am

      I left a reply, but my “comment is awaiting moderation”. I don’t know if that ever gets approved or if anyone other than me can see it.

      So, I’m posting a variant on the response to see if it goes through automatically.

      I recommend you see the code at my site:
      http://www.spectrum-nashville.com/reCAPTCHA/zimmertech

      It is based on a very good tutorial about adding Comments processing. When you go to my page, look for a link at the left which says “Zimmertech Contact Form tutorial”. Go read the tutorial first. The author actually has a back-link back to my page as well to send people here for the reCAPTCHA add-in.

      Hopefully this comment will post…. Good luck!

  370. tami / May 25 2010 10:04 am

    Need help. Don’t have time to read all the responses. Wish I did. I’m sure this has been covered but…..
    This is my code on my form page:

    or

    I get the recaptcha box to show but at the bottom of my page I get an error this error message:

    Warning: require_once(recaptchalib.php) [function.require-once]: failed to open stream: No such file or directory in /home/bjspark/public_html/request_form.php on line 379

    Fatal error: require_once() [function.require]: Failed opening required ‘recaptchalib.php’ (include_path=’.:/usr/lib/php:/usr/local/lib/php’) in /home/bjspark/public_html/request_form.php on line 379

    Line 379 is the require_once(recaptchalib.php) line and it doesn’t show up on my page in dreamweaver but does when I load it to the web. Why?

    This is my processing script:

    is_valid) {
    // What happens when the CAPTCHA was entered incorrectly
    die (“The reCAPTCHA wasn’t entered correctly. Go back and try it again.” .
    “(reCAPTCHA said: ” . $resp->error . “)”);
    }

    When I submit my form I get the following error message:

    Warning: require_once(recaptchalib.php) [function.require-once]: failed to open stream: No such file or directory in /home/bjspark/public_html/request_process.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/bjspark/public_html/request_process.php on line 2

    Again line 2 is the require_once(recaptchalib.php) line so it seems there’s something wrong with that function but I just copy/pasted the script. Can anyone help me with this please. If you want to look at my full webpage go to http://www.bjspark.com/request_form.php
    Thanks so much

  371. tami / May 25 2010 10:07 am

    Sorry but for some reason the form page code didn’t show in my last post so here it is:

    or

    Thanks again

  372. tami / May 25 2010 10:18 am

    Ok, don’t know why it won’t copy/paste but I’ll try again.

    <script type="text/javascript"
    src="http://api.recaptcha.net/challenge?k=mypublickey inserted here"

    <input name="Submit" type="submit" value="Submit Request"

    I hand typed this time so I hope it works.

    • Keith N. / May 25 2010 12:00 pm

      That error message simply means PHP cannot find the file named recaptchalib.php.

      You have to get that file from the recaptcha web site AND post it to your web server in the same folder/directory as your web pages that use recaptcha.

      The rest of your code is irrelevant until this problem is fixed, but if you end up still needing to post code, the best way to make the code show up in this blog is to wrap it in “code” tags.

      To do that, hand-type [code] on a line by itself. Then paste your code, then close it (just like in html) with [/code] on a line by itself.

      Good luck.

  373. caitlyn / May 26 2010 1:46 pm

    just wanted to say thanks, this is exactly what i needed to make recaptcha work!! This really breaks it down and makes it simple to understand where everything goes!

  374. james / May 29 2010 12:44 pm

    Thanks for the tutorial, this has really helped me get the re-captcha form up and finally get rid of most of the spam comments. Thanks again

  375. simona / Jun 1 2010 3:49 pm

    Please help, i wont to remove recaptcha from my site, can i do it?

  376. Alexandra / Jun 4 2010 7:36 am

    Hi, great tutorial!
    I’m actually using funcaptcha for joomla. I configured everything and i got recaptcha showing but for every captcha that i send gives error with wrong captcha.
    What could be the cause? It uses global enabled or something like this? Special permissions on dirs. I relly don’t know anymore in witch direction I should be looking.
    Thank you very much!
    Alex

    • Keith N. / Jun 4 2010 10:41 am

      Alexandra. If you’ve read all the comments appended to this tutorial, you’ll see there are a wide variety of possible reasons you could be experiencing this issue.

      Read through the comments; compare the posts to your experience. The answer is probably lurking in there somewhere.

      If you do that, and still don’t find the problem, you’ll have to post more details before anyone can offer any more help.

      I can say it is probably not a permissions problem, and it is probably not a globals-related issue. Neither of those typically have any impact on reCAPTCHA if your web site is working “normally”.

      Good luck.

      • Alexandra / Jun 6 2010 3:25 pm

        Thank you very much for your quick reply. I solved it and the strangest thing is that it was the tmp folder without the right permissions. It needs to be world writable. And still I don’t understand why….

        • Keith N. / Jun 6 2010 3:39 pm

          If the /tmp permissions truly were the issue, then I would have to assume that it has more to do with the joomla handling of form posts rather than actually a reCAPTCHA problem.

          Glad to hear that it is working, though, and now people trying to implement in joomla may be saved fighting the same problem by reading your post! Good stuff and thanks for posting back with that information.

  377. Ioan Virag / Jun 5 2010 2:58 pm

    Great tutorial. It took me five minutes to set everything up. Keep up the good work.

  378. Emre / Jun 7 2010 8:24 pm

    My form points to a file when i press the “send” button, this file is a perl script called xyz.pl , within a cgi-bin folder.

    1/
    Do I need to set the file permissions to 755 on the recaptchalib.php or leave them as 644 ?

    2/
    Do I also need to copy and put the recaptchalib.php file in the same directory as the xyz.pl script within the cig-fin folder ?

    3/
    Do I need to change the perl script to end in the extension .php from the .pl ?

    4/ When I paste the following code in my xyz.pl script
    on the first line. Then run the form, i get a server error upon pressing the “send” button which points to the xyz.pl
    script.

    is_valid) {
    die (“The reCAPTCHA wasn’t entered correctly. Go back and try it again.” .
    “(reCAPTCHA said: ” . $resp->error . “)”);
    }
    ?>

    5/
    What am I not getting ? do i need to create a separate file known as abc.php for the form processer file ? how can i get it to work if i am already using perl for the form processor ?

    • Keith N. / Jun 7 2010 9:01 pm

      PHP and Perl are two different languages. You will not be able to mix-and-match by putting the PHP code into the Perl files.

      From the recaptcha.net web site, I found this link:

      http://search.cpan.org/dist/Captcha-reCAPTCHA/lib/Captcha/reCAPTCHA.pm
      

      which purport to be a Perl implementation of the reCAPTCHA API.

      Maybe that will help.

  379. troglobyte / Jun 8 2010 6:37 am

    Thanks! With your instructions it worked right away, and this was my first try at PHP!

  380. Raiquee / Jun 9 2010 12:06 pm

    Having problems with the code 😦 My form is on my contacttest.php page…and I have the captcha showing up and looking perfect. However when entering in things correctly, I get an error

    “is_valid) {die (‘The reCAPTCHA wasn’t entered correctly. Go back and try it again.’ . ‘(reCAPTCHA said: ‘ . $resp->error . ‘)’); } ”

    Here is my code from my submit.php

    
    <?php
    require_once('recaptchalib.php');
    $privatekey = '6Ldxk7oSAAAAAF4N4DmFaKqP_9hcae30PjeV-brr';
    $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 . ')');
    }
    ?>
    
    <?
    //  Change these to suit:
    $emailto = "rdaenterprises@wi.rr.com";
    $emailfrom = "rdaenterprises@wi.rr.com";
    $subject = "Contact form from USP";
    $successredir = "thanks.htm";
    $failredir = "error.html";
    
    // Leave the rest alone:
    $toreport = split(",", $_REQUEST["values"]);
    $message = "Input from website:\n\n";
    foreach ($toreport as $field)
    {
    	$message .= "$field:\t" . $_REQUEST[$field] . "\n";
    }
    if (mail($emailto, $subject, $message, "From: $emailfrom"))
    {
    	header("Location: $successredir");
    }
    else
    {
    	header("Location: $failredir");
    }
    ?>
    
    
    
    • Keith N. / Jun 9 2010 1:21 pm

      Have you confirmed that your form is using method=”post”?

      The remaining variables down past the reCAPTCHA in submit.php are accessed with $_REQUEST[] which implies the form may be using method=”get”.

      First thing would be to go back to contacttest.php and find the <form method="???" action="submit.php" and be certain method="post".

      • Raiquee / Jun 9 2010 1:34 pm

        Yes, it is post:

        <form action="submit.php" method="post" class="electricblue">
        

        taken from contacttest.php

        • Keith N. / Jun 9 2010 1:55 pm

          Ah, now I do see a syntax error. In the message string on line 9, you cannot have the apostrophe like this:

          ‘The reCAPTCHA wasn’t …

          Either put double-quotes around the error message, or put a backslash directly before the apostrophe.

          As it stands, PHP will think the string ends after the “wasn” part.

  381. Raiquee / Jun 10 2010 8:11 am

    Keith,

    (First let me say, thank you so much for the help!!)

    I did that, but now I am getting this error:

    “Warning: Cannot modify header information – headers already sent by (output started at /home/planman51/domains/uniquestoneproducts.net/public_html/submit.php:1) in /home/planman51/domains/uniquestoneproducts.net/public_html/submit.php on line 31”

    Line 31 is the same as line 31 in my original post. Also as a side node, I got this warning after filling in the form, filling in the Captcha CORRECTLY and hitting submit. The form still reached the mailbox.

    • Keith N. / Jun 10 2010 4:22 pm

      The header warning problem is caused by Line 13. Between the first PHP closing block on line 12:
      ?%gt;

      and the next PHP opening block on line 14:
      <?php

      There is a line of whitespace that is going to the browser. That’s all it takes to get ther header warning. You could just delete lines 12,13,14 and make one big PHP block to avoid the extra whitespace.

      Since it was only a “warning”, the PHP continued to process, thus the email was sent out in spite of the header warning.

      • Raiquee / Jun 11 2010 8:03 am

        Keith,

        Now I get this:

        
        is_valid){ die ('The reCAPTCHA wasn\'t entered correctly. Go back and try it again.' . '(reCAPTCHA said: ' . $resp->error . ')'); } // Change these to suit: $emailto = "rdaenterprises@wi.rr.com"; $emailfrom = "rdaenterprises@wi.rr.com"; $subject = "Contact form from USP"; $successredir = "thanks.htm"; $failredir = "error.html"; // Leave the rest alone: $toreport = split(",", $_REQUEST["values"]); $message = "Input from website:\n\n"; foreach ($toreport as $field) { $message .= "$field:\t" . $_REQUEST[$field] . "\n"; } if (mail($emailto, $subject, $message, "From: $emailfrom")) { header("Location: $successredir"); } else { header("Location: $failredir"); } ?>
        
        

        when I enter the form, and it doesn’t appear as the form went through. The captcha was correctly.

        • Raiquee / Jun 11 2010 8:04 am

          if you want to try giving it a whirl, the addy is:

          http://www.uniquestoneproducts.net/contacttest.php

          maybe if you view the source you can get an idea of any issues.

        • Keith N. / Jun 11 2010 2:16 pm

          I browsed over to the link and filled out the contacttest.php form.

          When I did it, I got the header() warning:

          Warning: Cannot modify header information – headers already sent by (output started at /home/planman51/domains/uniquestoneproducts.net/public_html/submit.php:1) in /home/planman51/domains/uniquestoneproducts.net/public_html/submit.php on line 28

          Of course, now it is complaining about line 28, so I assume that means you removed the old 12,13,14 lines (the error message formerly pointed at 31, so 3 lines removed gives 28).

          The error message implies output started at line 1 on submit.php, so I’m wondering if there is anything in submit.php PRIOR to the very first open php tag in your posted code.

          Remember, even a blank line or a space before the <php will make the header() warning happen.

          Unfortunately, View Source doesn’t show any useful information in this instance.

  382. mido / Jun 12 2010 10:54 am

    hi
    sorry to be boring.. thanks for your helping post and blog, i try to use this script on my php pages… i’m a beginner…

    while i copy the little php code inside my contact form, just before my “send” button, this button just go away and nothing appear

    i get a private key and public key, my files are all .php, i’ve done some stuff in php before but dont find a way to solve my situation…

    thanks if you can help in any way.
    see you

    • Keith N. / Jun 12 2010 2:46 pm

      You’ll probably have to post code if you still need any assistance.

      A wild guess from me: if your Send button suddenly disappeared, you may have left off a closing brace — } — or a closing PHP mark:
      ?>

      Take a good close look to be certain you have a “close” for every “open”. Good luck!

      • mido / Jun 15 2010 4:43 am

        hi
        i find out what was wrong 🙂

        it works online but not on my localhost… something about lib and server i guess, my other php files are ok on my localhost, i’ll find out what to do about this and post here the “solution”, maybe it can help someone else

        thanks for replying
        see you

        • mido / Jun 16 2010 5:15 am

          Arf
          now the picture appear well on my page

          but whatever i enter it’s always replying “wrong wrong wrong wrong…”

          i search a little the web about this issue, not that much info

          i tried to generate another key but it says still “wrong wrong wrong”

          anyone know another way to generate safe form for a website… it seems to be pretty boring to include a simple safe contact form this days..

          i’m gonna write my postal address on my “contact page” 🙂

          i stay tuned about any good news and will give mine if i get any, see ya

          bises

  383. Barry / Jun 14 2010 8:02 am

    Got the code in and displaying correctly in ie but not in chrome or firefox. tells me: Input error: Invalid referer?

    • mido / Jun 16 2010 5:19 am

      i guess you host your site somewhere and redirect you .com to another web address, you have to give the absolute address to captcha

      i mean, if your stuff.com is hosted on mypersonalwebpage.myisp.com you have to give mypersonalwebpage.myisp.com to captcha

      try it
      see you

  384. Bruzbuzz / Jun 16 2010 4:14 pm

    I think your CAPTCHA is very easy to implement and your instructions are quite complete, if you read them carefully, and put the code in the right places. Thanks. One thing though… is there a way to tweak the width of the CAPTCHA?? I would prefer it were not so wide; not a biggie. Later.

  385. riyadh / Jun 19 2010 11:48 pm

    thx… very helpfull

  386. Stephanie / Jun 21 2010 4:40 pm

    I am making some edits to an existing form including adding a captcha. Thank you for the tutorial, it saved me! Problem I have now is that when you try to select the content box for the captcha, it goes back to the text box above it. Any ideas? Pretty dumb but I’m afraid of it causing end user problems.

    Thanks so much!

  387. surfkitten / Jun 21 2010 6:35 pm

    I keep getting the following error and I can not figure out what I am missing or more than likely did wrong: “Fatal error: Call to undefined function recaptcha_check_answer() in D:\Hosting\4555029\html\recaptchalib.php on line 24”

    • Keith / Jun 21 2010 8:26 pm

      The most likely cause of this problem is that you don’t have this:
      include(‘recaptchalib.php’);
      or this:
      require_once(‘recaptchalib.php’)

      in the PHP file where your form lives.

      • surfkitten / Jun 25 2010 6:37 pm

        Thank you so much for the help!!! It fixed my one error and now I have somehow generated ANOTHER error.

        Fatal error: Call to undefined function recaptcha_get_html() in D:\Hosting\4555029\html\recaptchalib.php on line 6

        I don’t even know what question to ask in relation to this error. I am hoping you can tell me just by the error msg itself. Ugh!

        • Keith / Jun 25 2010 8:43 pm

          This is essentially the same error but triggering on a different function. The recaptcha_get_html() function is defined inside the recaptchalib.php file provided by the folks at recaptcha.net.

          Have you been editing anything inside the recaptchalib.php file? If so, you should go get the original again from recaptcha.net and start with a clean slate (you should not make any edits inside this file at all).

          Otherwise, it still sounds like an include(‘recaptchalib.php’) issue. If that php file is being “included” — either with the include() function or the require_once() function — then all the recaptcha functions will be defined properly.

          Sorry, that’s as close as I can get without actually seeing the code in question.

  388. Keith / Jun 21 2010 8:22 pm

    I haven’t looked at the source in depth, but that looks like javascript moving the focus back to the Comments field; it definitely is not an ordinary behavior of reCAPTCHA.

    I would start by checking all the external scripts very closely, especially those with “focus” features in them.

    • Keith / Jun 21 2010 8:24 pm

      This was intended to be a reply to Stephanie regarding the walkinyourgreatness.com contact page…. Somehow I ended up posting without “replying”. Sorry.

  389. none / Jun 23 2010 5:50 pm

    got recaptcha box to pop-up but you dont have to enter a code to post. Please Help?

    http://www.goodvibesracing.com/parts_wanted1.php

    Thank You

    • Keith / Jun 23 2010 7:30 pm

      From what I can tell by looking at the page, you’re attempting to use a simple link to your php with the reCAPTCHA, which isn’t going to work. On your page, the suspicious code looks like this:

      <a href="php_scripts/parts_for_sale_test_form.php"> 
      	<font size="5" color="#0000FF">Add Performance Parts</font>
      </a>
      

      The “a” tag doesn’t have any idea that it needs to transfer data from the reCAPTCHA fields to the next page. The reCAPTCHA requires a FORM (there are other, more complex ways, but let’s stick with “requires a form” for now) with the action set to go to your PHP file. This way, the reCAPTCHA data is sent along.

      Something like this:

      <?php require_once('recaptchalib.php'); ?>
      
      <form action="php_scripts/parts_for_sale_test_form.php" method="post">
         <?php echo recaptcha_get_html(API_PUBLIC_KEY); ?>
         <input type="submit" value="Add Performance Parts" />    
      </form>
      

      The recaptcha_get_html() and the input button both MUST be inside the form, at a minimum.

      You can style the submit button with inline CSS to make it look like a regular link if you want, but leaving it as a button isn’t really such a bad idea either.

      Good luck.

  390. none / Jun 24 2010 12:13 pm

    Hello Keith,

    Thanks for the help. I have another question, when i put (your code) it comes up on my web site as the PHP code. Do i have to get an API Public Key code? Also when I put in this code:

    is_valid) {
    die (“The reCAPTCHA wasn’t entered correctly. Go back and try it again.” .
    “(reCAPTCHA said: ” . $resp->error . “)”);
    }
    ?>

    In any of my forms or web pages (which I put at the top of the PHP code like it says to do in the instructions) It always comes up with this error: The reCAPTCHA wasn’t entered correctly. Go back and try it again.(reCAPTCHA said: incorrect-captcha-sol) Am i putting the code in the wrong location?

    Thank you for your time and help

    • Keith / Jun 24 2010 1:41 pm

      Let me answer your last question first: The validation code may be working correctly, but it will be hard to tell until the form is posting the correct data. So, I can’t say with certainty yet whether it is right, because I think you still have problems where the reCAPTCHA box is displaying.

      Now, back to the beginning…. Yes, you must apply for and use your own Public and Private API keys. I think you have done that, based on looking at your page, but I can’t see your PHP code, so I am not certain. In any event, where I had “API_PUBLIC_KEY” in my source snippet above, you must provide your own public key, enclosed in quotes.

      I’m not sure what you mean by “it comes up on my web site as the PHP code”. I browsed the page and did not see this behavior — in fact, it initially looked pretty good.

      I did notice, however, that your reCAPTCHA fields are currently not inside the form tags, so the reCAPTCHA data is still not being forwarded to the validation page. Notice in my second snippet above, the <form … > tag comes before any reCAPTCHA stuff.

      Give it another look with that info at hand. I think you’re very close (but this isn’t horseshoes…).

      Good luck.

  391. none / Jun 24 2010 4:10 pm

    Hello Keith,

    As you can tell im not to hip on this. Here is a hyperlink to the page that i am putting the recaptcha box on. Thank you for your time

    http://www.goodvibesracing.com/php_scripts/testcapatcha.htm

    • Keith / Jun 24 2010 4:49 pm

      OK, first question: are you putting reCAPTCHA on a page with an .htm or .html extension? On most web servers, any time you have PHP code in your document (usually with the <?php … ?> tags), you need to change that file to have a .php extension for it to be interpreted correctly.

      Then, you can delete this block of code:

      <?php
      require_once('php_scripts/recaptchalib.php');
      $publickey = "MY PUBLIC KEY"; // you got this from the signup page
      echo recaptcha_get_html($publickey);
      ?>
      

      because you have redundant code below it that should work:
      (keep this code)

      <?php require_once('php_scripts/recaptchalib.php'); ?> 
      <form action="php_scripts/parts_for_sale_test_form.php" method="post"> 
      <?php echo recaptcha_get_html(MY PUBLIC KEY); ?><input type="submit" value="Add Performance Parts" /> 
      </form> 
      

      BUT you do still have to have our own API keys. In the second code snippet here, you need to replace MY PUBLIC KEY with your actual public key that you obtain from recaptcha.net.
      The key will need to be in quotes. So for example, if recaptcha.net gave you a public key of ABCDEFG12390131ASD, then the code might look like this:

      <?php require_once('php_scripts/recaptchalib.php'); ?> 
      <form action="php_scripts/parts_for_sale_test_form.php" method="post"> 
         <?php echo recaptcha_get_html("ABCDEFG12390131ASD"); ?>
         <input type="submit" value="Add Performance Parts" /> 
      </form> 
      

      That is not a valid Public key, by the way, but the public key will be a long string of alpha-numeric characters like that….

      When you get around to making your validation code work, it will require a Private key (you get both from recaptcha.net at the same time — they work as a pair). Just be aware….

  392. none / Jun 24 2010 5:22 pm

    Hello Keith,

    Thank You it works perfect!!! have a good one

  393. ay / Jun 29 2010 9:24 pm

    Hi there, I installed this and it seemed to work at first, however, now I see that the form data is entered into my database even if the code is not entered correctly. if they have to re enter the code then the data is entered into the database twice! so basically it is pointless to have this as is, please help!

    • Keith / Jun 29 2010 9:38 pm

      Given that the system is known to work elsewhere, we must assume you have some kind of error in your implementation…

      Can you provide some details … maybe some code snippets … that someone might be able to help troubleshoot?

  394. Chrisa / Jul 2 2010 8:00 am

    I am having a problem where everything works EXCEPT if you click submit and dont fill anything out on the capcha box it sends the email anyways. Any ideas what I am doing wrong? is there a die i should be entering?


    is_valid) {
    ?>
    Thank you for your submission!
    is_valid) {
    die (" PLEASE RE-ENTER THECAPCHA CODE Back" .
    "(reCAPTCHA said: " . $resp->error . ")");
    } else {
    # set the error code so that we can display it
    $error = $resp->error;
    ?>

    • Keith / Jul 3 2010 3:26 pm

      Can you retry to post your code? When you paste the code, surround it with “code” tags like this:
      [code]
      // paste your code in here and the blog software won’t butcher it up….
      [/code]

  395. Hurst Vanrooj / Jul 12 2010 6:02 am

    Hi there – great tutorial – It all works well for me. I’d like to add something to the form. At the moment a failure re-direct BACK TO THE ORIGINAL FORM like so
    http://www.example.com/contact.php?result=fail

    Great the error message works. But the info has been lost from the input boxes. Would I have to create a session to keep them? If anyone could just point me in the right direction, that would be helpful.

    • Keith / Jul 12 2010 8:36 am

      A session variable won’t really help you out, and but you can’t do what you’r suggesting with the reCAPTCHA implemented in 2 separate PHP files the way it is shown in this tutorial.

      See this single-file implementation demo to set it up exactly the way you are suggesting:
      http://www.spectrum-nashville.com/reCAPTCHA/demo.php

      Everything in one file means you can retrieve the $_POST[] variables from the forms and put them BACK into the form with the value=”” attribute on your input tags.

      Good Luck.

      • Keith / Jul 12 2010 9:11 am

        One clarification: yes, you could use SESSION variables, now that I think about it.

        You’d have to store your POST variables into SESSION variables in the second form before you start validating the CAPTCHA. Then you’d have to use those SESSION values to populate your form.

        My guess is you’d get into some problems with caching doing it that way, though, so I’d seriously recommend looking at changing to the single-file method.

  396. Hurst Vanrooj / Jul 13 2010 4:36 am

    KEITH – Thanks for the demo link – I’ll try that out. Last night I managed to wrap a Forms to Go error message inside the (!$resp->is_valid) { section which does the job pretty well. However, I will look at the demo code to see how it’s done correctly!

    Thanks
    Vanrooj

  397. Andy / Jul 13 2010 9:25 am

    Many thanks for this tutorial. It was much simpler to follow.

    I’m having a problem when testing my form though:

    If I enter completely wrong values – the form doesn’t get submitted.

    If I enter the correct values – the form does get submitted.

    If I enter NEARLY correct values (perhaps one character is wrong) – the form still gets submitted.

    Should reCAPTCHA let nearly correct values through?

    • Keith / Jul 13 2010 9:53 am

      There are several posts about this “feature” here, I believe, and there is an official reCAPTCHA note somewhere addressing this, too, but I forgot where.

      The upshot is this: only the first word truly has to be correct (the second word is a guess-word that reCAPTCHA is still trying to define). Additionally, the folks at reCAPTCHA are constantly “refining” what level of accuracy is required on the first word. They apparently never require 100% accuracy.

      So, you will see near-miss words get through the reCAPTCHA at varying levels of required accuracy.

      This is documented as a convenience feature that makes it easier for humans to get through without being bothered by a typo. Whether it is truly a feature is a subject of much debate.

      good luck!

  398. Ruth / Jul 13 2010 12:29 pm

    Hi
    I’m struggling with my re-captcha saying: The reCAPTCHA wasn’t entered correctly. Go back and try it again.(reCAPTCHA said: incorrect-captcha-sol)

    Could you check my site for me?
    http://www.rufflemedia.co.uk/new/contact.php

    Its a test page for my new contact page.

    I have attempted to try all the suggestions above but to no avail!

    Your help would be much appreciated!
    Ruth 🙂

    • Keith / Jul 13 2010 3:17 pm

      It’s impossible to determine the problem by browsing to the page, because the PHP code is already interpreted and rendered into the resulting HTML.

      You may need to post the code for your sendEmail.php file for review.

      • Ruth / Jul 14 2010 5:29 am

        Hi Keith

        Thanks. Here’s the code in my sendEmail.php file. I’ve omitted my private key and gmail details for obvious reasons!

        is_valid) {
        die (“The reCAPTCHA wasn’t entered correctly. Go back and try it again.” .
        “(reCAPTCHA said: ” . $resp->error . “)”);
        }
        ?>

        $name = trim($_POST[‘name’]);
        $email = $_POST[’email’];
        $comments = $_POST[‘comments’];

        $site_owners_email = ‘rufflemedia@gmail.com’; // Replace this with your own email address
        $site_owners_name = ‘Ruth Pryce’; // replace with your name

        if (strlen($name) < 2) {
        $error['name'] = "Please enter your name";
        }

        if (!preg_match('/^[a-z0-9&\'\.\-_\+]+@[a-z0-9\-]+\.([a-z0-9\-]+\.)*+[a-z]{2}/is', $email)) {
        $error['email'] = "Please enter a valid email address";
        }

        if (strlen($comments) From = $email;
        $mail->FromName = $name;
        $mail->Subject = “Website Contact Form”;
        $mail->AddAddress($site_owners_email, $site_owners_name);
        $mail->Body = $comments;

        // GMAIL STUFF

        $mail->Mailer = “smtp”;
        $mail->Host = “smtp.gmail.com”;
        $mail->Port = 587;
        $mail->SMTPSecure = “tls”;

        $mail->SMTPAuth = true; // turn on SMTP authentication
        $mail->Username = “my email”; // SMTP username
        $mail->Password = “my password”; // SMTP password

        $mail->Send();

        echo ” Congratulations, ” . $name . “. We’ve received your email. We’ll be in touch as soon as we possibly can! “;

        } # end if no error
        else {

        $response = (isset($error[‘name’])) ? “” . $error[‘name’] . ” \n” : null;
        $response .= (isset($error[’email’])) ? “” . $error[’email’] . ” \n” : null;
        $response .= (isset($error[‘comments’])) ? “” . $error[‘comments’] . “” : null;

        echo $response;
        } # end if there was an error sending

        ?>

  399. Sjeffers / Jul 13 2010 2:21 pm

    Okay, ffs, did some research, try to copy exactly the way described above, but I did not help. I also have the problem ‘The reCAPTCHA wasn’t entered correctly. Go back and try it again.(reCAPTCHA said: incorrect-captcha-sol)’. After al those hours, I’m not sure anymore where the problem lies, and I need a fresh look on ‘my case’. Can anyone help me?

    Thanks a lot,

    Sjeffers

    • Keith / Jul 13 2010 3:19 pm

      For better or worse, the tutorial code does work, so the problem is a typo or other slight syntax error in your implementation of it.

      If you post code from both your form page and your processing page, maybe a fresh set of eyes can spot the bug.

      • Sjeffers / Jul 14 2010 3:23 am

        process file: is_valid) {
        die (“The reCAPTCHA wasn’t entered correctly. Go back and try it again.” .
        “(reCAPTCHA said: ” . $resp->error . “)”);
        }
        ?>

        form page:

        I’m pretty newb in the scene so I’m not sure this is enough.

        Thanks anyway

  400. Sjeffers / Jul 14 2010 3:28 am

    Wait, that did not go so very well. I posted the files on megaupload. It over here: http://www.megaupload.com/?d=IKHE6ZYJ

  401. Sjeffers / Jul 15 2010 4:34 am

    Hi again,

    Somehow the recaptcha is on my page, but It is not working correctly, it still let’s spam through. I am pretty newb at this PHP scene, can someone help me out with my code?

    Spanx

    • Keith / Jul 21 2010 8:01 am

      Sorry it took a week to get back — I was traveling on business and had very little time to look at anything else.

      I downloaded your code and looked at it. I fixed up the reageren.php file and made it work correctly. I removed references to your old CAPTCHA and patched up a few code errors.

      You can see it work here:
      http://www.spectrum-nashville.com/test/reageren.php

      You can download the working php file here:
      http://www.spectrum-nashville.com/test/reageren.zip

      I’ll leave these posted for a week or two (or until you let me know you downloaded them already).

      The contact.php file is not used at all.

      Good luck with it.

      • Sjeffers / Jul 21 2010 1:45 pm

        Wow, you are brilliant. I uploaded the php and it works! It’s ALIVE! Was I far off the regular code?

        Thanks man.

        • Keith / Jul 21 2010 2:02 pm

          It was not far off. First, there was some pre-existing code about a different CAPTCHA that I removed.

          Also, it took a bit of reading to accurately hook the error message for reCAPTCHA into the existing method of stuffing error messages into $aFout so they appear as bullets on the page (that can be seen in the very first part of php code at the top of the file).

          Once those pieces were handled, it was ready to go. Enjoy!

          • Sjeffers / Jul 21 2010 2:55 pm

            Oh yeah I can see it now. Afterwards it’s easy talking, right? The spam is held of until now, so I my hopes are high!

            Jaap

    • Keith / Jul 21 2010 8:17 am

      My original reply is “awaiting moderation”, so I browsed to your web site and sent an email to the info@… address.

      Hopefully you found the email with your solution attached.

  402. Steffen / Jul 15 2010 7:43 am

    hi, its a very n1 guide!
    but one question i have. how can i change the style? with the theme clear it will works but in the guide by wiki u should change #…. things in a css file, but where is this file and where can i change this 🙂

  403. codef0rmer / Jul 16 2010 12:35 am

    Nice post.

    Is there any way to remove the logo and the line ‘stop spam, read books’ RHS.

  404. loveleen kaur / Jul 20 2010 11:17 pm

    hey m using your recaptcha coding and it going fine
    but while doing customization for theme of recaptcha it too goes well but after it shows message given below which is generated through javascript tag:

    Input error: k: Format of site key was invalid

    i m also sending code here:

    var RecaptchaOptions = {theme: ‘custom’, custom_theme_widget: ‘recaptcha_widget’};

    <form name="frm1" method="post" action="/email-o1.php”>

    Full Name*:

    Email Address*:

    Phone Number:

    Brief description:

    Spam Filter (Type the text from image to textbox)

    Incorrect please try again


    <img src="/images/refresh.gif”>

    <input type="image" src="/images/frm-submit.png” name=”Submit” onclick=”return validate();” />

  405. loveleen kaur / Jul 20 2010 11:24 pm

    hey m using your recaptcha coding and it going fine
    but while doing customization for theme of recaptcha it too goes well but after its custom display image it shows message given below which is generated through javascript tag:

    Input error: k: Format of site key was invalid

    i m also sending code here:

    <script type= "text/javascript">
    var RecaptchaOptions = {theme: 'custom',  custom_theme_widget: 'recaptcha_widget'};
    </script>
    
    <form name="frm1" method="post" action="<?php bloginfo('template_directory'); ?>/email-o1.php">
    			<table border="0" width="100%" id="table12" cellspacing="4" cellpadding="0" style="float:left;">
    				<tr>
    					<td align="right" style="width: 106px">Full Name*: </td>
    					<td width="205"><input name="fname" id="fname"  type="text" size="35"></td>
    				</tr>
    				<tr>
    					<td align="right" style="width: 106px">Email Address*: </td>
    					<td width="205"><input name="email" id="email" type="text"  size="35"></td>
    				</tr>
    				<tr>
    					<td align="right" style="width: 106px">Phone Number: </td>
    					<td width="205"><input name="phone"  type="text"  size="35" style="height:32px;"></td>
    				</tr>
    				<tr>
    					<td align="right" valign="top" style="width: 106px">Brief description: </td>
    					<td width="205"><textarea  name="resume"  rows="5" cols="22"></textarea><br /></td>
    				</tr>
    				<tr>
    					<td align="center" valign="top" colspan="2">
                        Spam Filter <i style="font-size:11px;">(Type the text from image to textbox)</i>
                        </td>
    				</tr>
                    <tr>
                    	<td align="center" valign="top" colspan="2">
                    	<?php
                        	require_once('recaptchalib.php');
    						$publickey = "6Ld1n7sSAAAAAPHROlwXasE6rBOi8GLF6RS94KXw"; // you got this from the signup page
    						echo recaptcha_get_html($publickey);
    					?>
                        <div id="recaptcha_widget" style="display:none">
                        
                           <div id="recaptcha_image" align="left"></div>
                           <div class="recaptcha_only_if_incorrect_sol" style="color:red">Incorrect please try again</div>
     					                  
                           <input type="text" id="recaptcha_response_field" name="recaptcha_response_field" size="30"/>
     					   <a href="javascript:Recaptcha.reload()">
                           <img src="<?php bloginfo('template_directory'); ?>/images/refresh.gif"></a>                   
                         </div>
                        
                         <script type="text/javascript" src="http://www.google.com/recaptcha/api/challenge?k=your_public_key">
                         </script>
                         <noscript>
                         <iframe src="http://www.google.com/recaptcha/api/noscript?k=your_public_key" height="300" width="500" 			                             frameborder="0">
                         </iframe><br>
                         <textarea name="recaptcha_challenge_field" rows="3" cols="40"></textarea>
                         <input type="hidden" name="recaptcha_response_field" value="manual_challenge">
                         </noscript>
                    	</td>
                    </tr>
                    <tr>
                    	<td width="150" align="left" colspan="2" style="padding:10px 0px 0px 162px;">
                        <input type="image" src="<?php bloginfo('template_directory'); ?>/images/frm-submit.png" name="Submit" onclick="return validate();" /><br />
                        </td>
                    </tr>
               </table>
           </form>
    
        
    • Keith / Sep 11 2010 7:59 am

      I think I answered this same question on the Google Groups for reCAPTCHA. But just in case, I recommend looking at line 45 in the source above. Change the key on the javascript line.

  406. Be part of the Cloud / Jul 29 2010 4:12 am

    Thanks for the post. Getting sick of spammers!

  407. Josh Wilcox / Sep 10 2010 5:06 pm

    I have multiple websites and i am just using a test form on this site, freeeverify.info. I did everything exactly the way you said in your tutorial but occationally i get Input error: Invalid referer instead of the actual captcha widget. Sometimes it shows the captcha widget but i get that error message inside the box instead of the image of the warped text.

    What do I do to fix it?

    • Keith / Sep 11 2010 7:58 am

      Sorry I can’t give you a quick fix, but here is a different plan for finding one (maybe).

      reCAPTCHA is now a property of Google, so things have changed since this original tutorial was written. The Google folks have a Group for support of reCAPTCHA, where you can often search and find answers to your questions. There is also additional documentation there.

      http://groups.google.com/group/recaptcha/topics

      You’ll have to sign up to see the forums, I think, but it may be worth it.

      Good luck.

  408. Jrich / Jan 8 2011 10:03 pm

    Thanks for the tips: Well Documented . You too saleem

  409. Geoff Jackson / Jan 17 2011 11:12 am

    Got this installed for a clients website today, took a number of hours to get it right but your article proved very helpful to get it sorted, thanks!

  410. Greg M. / Jan 21 2011 8:17 pm

    I’m getting this error when I try to use recaptcha:
    I’ve checked my keys and they are copied and pasted directly from the recaptcha site.

    Input error: k: Format of site key was invalid

    Help would be apreciated.

  411. Cynthia / Jan 23 2011 10:45 pm

    Hello,
    I’ve been using recaptcha successfully for quite awhile now and all of a sudden a problem has popped up and I need help. The recaptcha input box (the white box where the user types the recaptcha text) appears below the recaptcha blackglass theme box. I have never seen this before and it only does it in IE7 all other versions and browsers work just fine. Has anyone had this problem and if so found an answer? Any help would be appreciated, I’m pulling my hair out.

    Thanks!

  412. Tim / Jan 24 2011 12:23 pm

    I am somewhat new to php but I am trying to utilize Recaptcha in my website. I already have scripting that provides me with the user’s email address as a variable but I need scripting that will take that variable and using Recaptcha behind the scenes – return a URL for that address as a variable that can be attached to the the user’s classified ad without any additional effort on the part of the user. I’m sure that this can be done, but like i said earlier, I’m kinda new to this and being currently unemployed, I can’t afford to pay a programmer at this time. Any help would be extremely appreciated. Thanks !!

  413. Saelon / Feb 24 2011 1:23 am

    You must be tired of this by now, but I hope you will help me anyway. Your page is the first thing I’ve found that clarified most of the code. My form.php and process.php both appear to be basically working, but I although I’m trying to set this up as a version of formmail, I don’t actually get anything from it, probably because I can’t figure out where the hell I’m supposed to tell this thing to send the results to me or where to give it my email address. I put the form at http://www.saelon.com/recaptcha/form.php. Maybe you can tell me what I’ve left out? Thanks!

  414. Scarface / Feb 24 2011 10:30 am

    Thank you very well

  415. Sheila / Mar 28 2011 1:42 pm

    Tries everything and still getting “The reCAPTCHA wasn’t entered correctly. Go back and try it again.(reCAPTCHA said: incorrect-captcha-sol)”

  416. telecommunication book / Apr 10 2011 9:49 pm

    useful tutorial, best thanks for this and hope will reduce spam on my blog.

  417. geldeasy / Apr 12 2011 3:42 pm

    The simple truth is, in life, lots of people know what to do, but handful of people truly do what they know. Knowing is not enough! You have got to make a change

  418. globy / Apr 13 2011 1:25 pm

    I’ve tried it and works just fine for me.
    I used to get “Input error: k: Format of site key was invalid” too, but somehow this is gone now.
    hope it stays that way 🙂

    G.

  419. SOL / Apr 19 2011 10:02 am

    hey..

    I’m have a problem with “recaptcha_challenge_field” & “recaptcha_response_field” showing up in my message body.

    someone else had the same problem and they were told to check for $_POST or $_REQUEST in the part of their code that builds the message..

    unfortunately, i can’t get this fixed.

    here is what my mail.php code looks like

    is_valid) {
    // What happens when the CAPTCHA was entered incorrectly
    die ("The reCAPTCHA wasn't entered correctly. Go back and try it again." .
    "(reCAPTCHA said: " . $resp->error . ")");
    } else {
    // Your code here to handle a successful verification
    }
    ?>

    64 || empty($exploded_email[1])){$errors[] = "Email address is invalid";}else{if(substr_count($exploded_email[1],".") == 0){$errors[] = "Email address is invalid";}else{$exploded_domain = explode(".",$exploded_email[1]);if(in_array("",$exploded_domain)){$errors[] = "Email address is invalid";}else{foreach($exploded_domain as $value){if(strlen($value) > 63 || !preg_match('/^[a-z0-9-]+$/i',$value)){$errors[] = "Email address is invalid"; break;}}}}}}

    }

    // Check referrer is from same site.

    //if(!(isset($_SERVER['HTTP_REFERER']) && !empty($_SERVER['HTTP_REFERER']) && stristr($_SERVER['HTTP_REFERER'],$_SERVER['HTTP_HOST']))){$errors[] = "You must enable referrer logging to use the form";}

    // Check for a blank form.

    function recursive_array_check_blank($element_value)
    {

    global $set;

    if(!is_array($element_value)){if(!empty($element_value)){$set = 1;}}
    else
    {

    foreach($element_value as $value){if($set){break;} recursive_array_check_blank($value);}

    }

    }

    recursive_array_check_blank($_REQUEST);

    if(!$set){$errors[] = "You cannot send a blank form";}

    unset($set);

    // Display any errors and exit if errors exist.

    if(count($errors)){foreach($errors as $value){print "$value";} exit;}

    if(!defined("PHP_EOL")){define("PHP_EOL", strtoupper(substr(PHP_OS,0,3) == "WIN") ? "\r\n" : "\n");}

    // Build message.

    function build_message($request_input){if(!isset($message_output)){$message_output ="";}if(!is_array($request_input)){$message_output = $request_input;}else{foreach($request_input as $key => $value){if(!empty($value)){if(!is_numeric($key)){$message_output .= str_replace("_"," ",ucfirst($key)).": ".build_message($value).PHP_EOL.PHP_EOL;}else{$message_output .= build_message($value).", ";}}}}return rtrim($message_output,", ");}

    $ip = $_SERVER['REMOTE_ADDR'];

    $message = build_message($_REQUEST);

    $message = $message . PHP_EOL.PHP_EOL."-- ".PHP_EOL."";

    $message = stripslashes($message);

    $subject = "Email from Gamer's Paradise";

    $headers = "From: " . $_REQUEST['email'];

    mail($my_email,$subject,$message,$headers);
    ?>
    </code

    • SOL / Apr 19 2011 10:04 am

      sorry.. some of the code got cut out.. but i think the important part is there to see.. 🙂

    • Keith / Apr 19 2011 10:39 am

      Your problem is in the build_message function

      function build_message($request_input) {
      if(!isset($message_output)){
      $message_output ="";
      }
      if(!is_array($request_input)) {
      $message_output = $request_input;
      }
      else {
      foreach($request_input as $key => $value) {
      if(!empty($value)) {
      if(!is_numeric($key)) {
      $message_output .= str_replace("_"," ",ucfirst($key)).
      ": ".build_message($value).PHP_EOL.PHP_EOL;
      }
      else {
      $message_output .= build_message($value).", ";
      }
      }
      }
      }
      return rtrim($message_output,", ");
      }

      It is including everything from the URL request in your emal message.

      Change it to look like this:

      function build_message($request_input) {
      if(!isset($message_output)){
      $message_output ="";
      }
      if(!is_array($request_input)) {
      $message_output = $request_input;
      }
      else {
      foreach($request_input as $key => $value) {
      if(!empty($value)) {
      if( strtolower(substr($key,0,5)) != 'recap' ) {
      if(!is_numeric($key)) {
      $message_output .= str_replace("_"," ",ucfirst($key)).
      ": ".build_message($value).PHP_EOL.PHP_EOL;
      }
      else {
      $message_output .= build_message($value).", ";
      }
      }
      }
      }
      }
      return rtrim($message_output,", ");
      }

      Notice the line that says: if( strtolower(substr($key,0,5)) != ‘recap’ )

      That should ignore any variable beginning with “recap”.

      Let us know if that works out for you.

      • SOL / Apr 19 2011 10:51 am

        worked like a charm 🙂

        thanks a lot.. you guys are to good

  420. Nick / May 10 2011 7:16 am

    Hi
    I have logged in google API and get public key and private key for captcha code…
    but after submitting the Captcha dilogue i have got this error…

    ReCaptchaResponse Object ( [is_valid] => [error] => invalid-site-private-key )

    althogh i have entered 3 times correct private key
    still it show this msg…

    plz help me…

    • Keith / May 10 2011 9:57 am

      Post some code and answer this question: are you using an AJAX interface or just “plain” PHP (or something else)?

      When you paste your code into the blog, be sure to enclose it in “code” tags, so it doesn’t get chopped up by the blog software.


      // this is enclosed in a code tag
      // it will be easier to read, reference, and copy/paste for troubleshooting
      if( true ) {
      echo "true!";
      }

    • Keith / May 10 2011 9:58 am

      Just testing here. The html-style code tag didn’t work, so I’ll try a bbcode-style code tag and see if that does the trick.

         // this is inside a bbcode-style code tag
         if( true ) {
            echo "true";
         }
      

      We’ll see….

    • Keith / May 10 2011 10:02 am

      OK … authoritative note about “code” tags. HTML tag style doesn’t work, so when you paste your code here, surround it with bbcode-style “code” tags.

      To do that, you type:
      [code\
      … paste your coe in here …
      [/code\

      Those square-bracket “code” tags will format your code correctly and help out by adding line numbers for references. It also gives a quick way to accurately copy/paste the code.

      Now, there you have it, post some code!

    • Keith / May 10 2011 10:04 am

      Sorry, one more time. This laptop keyboard is killing me today…. The code tags should look like this:

      [code]
      … paste your code in here …
      [/code]

      Hopefully I keyed it right this time. Sorry.

  421. jay / May 29 2011 2:01 pm

    very nice site thanks

  422. liomcr / Jun 29 2011 6:43 am

    Dude this guide is perfect for php dummies like me lol. And I still couldn’t manage to implement recaptcha to my download link. I’ve managed to place a recaptcha before my download link, but when I click to download, just downloads it, no need for a captcha verification. I hope I make the situation clear =D

  423. Matt / Jul 21 2011 11:44 pm

    Ahhh please help if you can. I just can’t seem to get this to go. I’m getting the following error:

    “Parse error: syntax error, unexpected T_REQUIRE_ONCE in /home/content/92/4824192/html/contactform.php on line 142”.

    • Keith / Jul 22 2011 12:23 pm

      Matt: the error message isn’t helpful if we can’t see the lines of code surrounding (and including) line 142. Try posting the lines of code around 142 in the contactform.php file, then maybe someone can spot the error for you.

  424. Andrew / Aug 18 2011 1:16 pm

    Hey, thank you very much for the tutorial. I got the reCaptcha working fine in IE and Chrome but in FF I get a “RecaptchaState is not defined” error and the page goes blank. I am using the reCaptcha in a jQuery popup form. From my research it seems the jQuery and reCaptcha don’t get along to well, but I am not sure why it doesn’t work only in FF. I wasn’t sure if you have come across this before or not. Thanks

  425. amira / Aug 22 2011 8:03 pm

    I bought 1 simple php code (web submission services), i tried to implement recapthca for form web submission, it doesnt work at all,

    Can you do it for me, i will pay you 20 USD,

    Please email me, thank you. I will send you code..

  426. Anna / Sep 16 2011 2:04 am

    Hi,

    I was trying to download the php library, but the link brought me to the empty search. Only when I chose “All downloads” and typed “php” I got the list of php libraries. But they were all deprecated; the lates one was recaptcha-php-1.10. Do you know how I can download the newest version for php?

    Thank you.

  427. Becka / Oct 6 2011 1:15 pm

    Hi. I have a form that I’ve put this into. I followed all directions. But when I type something (anything, even if it’s wrong) into the recaptcha box and hit the submit button, it goes to my “form sent successfully” thing and I get the form in my email anyway. It doesn’t say anything about the recaptcha doesn’t match or something. How do I fix this?

    • Keith / Oct 6 2011 2:51 pm

      The most common reasons for this are:
      (1) the recaptcha fields are not being placed inside the form (after the open form tag but before the close form tag), or
      (2) you’re missing a closing brace “}” in the process/validation part of your code.

      The only way for anyone to help you out with that is to look at your code. You can post code on this blog, or you can send me copies of your files if you want (keith at spectrum-nashville dot com).

  428. Seboon Chrises / Oct 21 2011 7:16 am

    me always getting the message The reCAPTCHA wasn’t entered correctly. Go back and try it again.(reCAPTCHA said: incorrect-captcha-sol), there is no method get the way out of it ,,,,,,,,,not showing any images of reCAPTCHA

    • Keith / Oct 21 2011 8:26 am

      Post more details and post code. You probably will get the error message every time if there was no image in the form to begin with. The problem is probably in your form page.

      Click my name above to see a working demo with downloadable code.

  429. Seboon Chrises / Oct 21 2011 11:08 pm

    hey the working demo showing such errors
    Warning: require_once(recaptchalib.php) [function.require-once]: failed to open stream: No such file or directory in D:\wamp\www\demo\demo.php on line 17

    Fatal error: require_once() [function.require]: Failed opening required ‘recaptchalib.php’ (include_path=’.;C:\php5\pear’) in D:\wamp\www\demo\demo.php on line 17

    • Keith / Oct 22 2011 3:54 pm

      You need the recaptchalib.php file placed on your web server (at d:\wamp\www\demo\) for it to work. You typically download the php file from reCAPTCHA when you sign up for your account.

  430. artistsamik / Nov 13 2011 5:06 am

    I believe still now there are many good people in this globe and you are one of them!

  431. Shelly / Jan 17 2012 3:06 pm

    Mere words cannot express my appreciation at how easy you’ve made implementing captcha into an existing form.

    THANK YOU!

    Shelly

  432. buhlah@hhotmail.com / Feb 25 2012 3:54 am

    The persons who wrote instructions at the reCAPTUPACHAHA website are as unintelligible as their name is.
    I think that your instructions would be much easier to follow, and I will give them a try.
    It is a shame that reCAPURACHA CHA does not hire a professional to organize their instructions so that more websites would use their product. As it is, visitors assume that people at reCATURAPACHA are insanely disorganized due to heroine addiction.
    Hopefully reCAPTTCHAHCHAHAHA will hire a man who has skills in organization and communication so that he would straighten out their incoherent mess. We would also hope that reCACHAHAPA would change their name to something that is intelligible.
    Honestly, customers only need to copy and paste HTML. It’s a no brainer, so rePUCHAHAHA should get off the techno-ego trip.

  433. GambleJoe / Apr 21 2012 4:25 pm

    The concept of reCAPTCHA is amazing and the idea is just brilliant! Thanks for that great Tutorial!

  434. ReSEOlve / May 16 2013 3:28 pm

    Very nice post and helpful tips look forward to read the next one is there any changes in 2013 regarding this or updates?

  435. Harry Herrlich / Oct 26 2013 8:53 am

    I got it, finally! Thanks for your great turtorial. I will add this to my site. Goodbye spammers 🙂

Trackbacks

  1. Stopping SPAM and contributing to a good cause… | Drift Web Design’s Blog
  2. Freelance Tip » Blog Archive » Easy install reCAPTCHA to your online forms.
  3. Designing a website for us HTML beginners
  4. ReCaptcha, Great Tool… Poor Documentation… | Jason Fisch
  5. Day 136 « The Road to Freelance
  6. Need some CAPTCHA help - SitePoint Forums
  7. Membuat Halaman Web yang menggunakan reCAPTCHA | Yesi Novaria Kunang

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: