Recaptcha 2.0 Will Not Verify Checking The Box

265 views
Skip to first unread message

Christopher Johnson

unread,
Oct 24, 2017, 3:11:45 PM10/24/17
to reCAPTCHA
Please help; I've been trying to get this to work for three days now. I've had a working site for recaptcha 1.0 for years that used a form to send me an email through PHP. Now they're dropping support for 1.0 and forcing everyone to use 2.0. I never could get 2.0 to work when it first came out, even though they said it was easier, so I just gave up and went back to 1.0. Now I have no choice but to switch.

I have been through five video tutorials and five website tutorials; all of which had comments from users saying it was very helpful and worked beautifully. Since I had a lot of problems editing my old code to the new code, I decided to start from scratch. I went back to these tutorials to use just their code, but my problem seems to be unique because I can't find anyone else asking about it.

I have PHP setup to echo an error message if the recaptcha box was not checked. It works if you don't check the box. The problem is when I test it, and I check the box, I STILL get that same error message. I have reviewed EVERYTHING, and I mean EVERYTHING. I even went back and rewrote the form code just in case. (I know that's not the source of the problem, but I did it anyway because I can't find another solution.) I have gone back through multiple tutorials of code; I checked every character to make sure I didn't type in anything wrong. I've put my code into site checkers for PHP and pulled up no errors. I've check and rechecked MANY times the copy and pasted code for the public/private keys Google recaptcha provides, and I cannot get past this error message that tells me I didn't check the box, even though I did.

If anyone knows anything about this problem, I would be very grateful for your help. Thank you.

Here are a couple of examples of code I've used just to give an idea of what I'm doing:
https://www.youtube.com/watch?v=xyOu0b6R3m0
(Again, this is just a couple of examples; I've tried many more sites' PHP code and I keep getting the same error.)

Christopher Johnson

unread,
Oct 24, 2017, 3:13:19 PM10/24/17
to reCAPTCHA
Oh, and before anyone asks, just to reverify -- I have entered the private/public keys properly. I've checked this more times than I can count.

Christopher Johnson

unread,
Oct 24, 2017, 4:08:47 PM10/24/17
to reCAPTCHA
Here's the code I currently have setup:

<table bgcolor="#ECECEC" width="99%" border="1" cellspacing="1" cellpadding="3"><tr><td align="center">
<table width="100%"><tr>
<! -- START CONTACT FORM -- >
<form name="contactform" method="post" action="sendemail.php">
<td valign="top" align="right"><label for="name">NAME:</label></td>
<td valign="top"><input type="text" style="font-size:18px; font-family:serif; name="name" maxlength="50" size="40"></td>
</tr><tr>
<td valign="top" align="right"><label for="location">LOCATION:</label></td>
<td valign="top"><input type="text" style="font-size:18px; font-family:serif; name="location" maxlength="50" size="40"></td>
</tr><tr>
<td valign="top" align="right"><label for="email">EMAIL:</label></td>
<td valign="top"><input type="text" style="font-size:18px; font-family:serif; name="email" maxlength="50" size="40"></td>
</tr><tr>
<td valign="top" align="right"><label for="message">TEXT:</label></td>
<td valign="top"><textarea name="message" style="font-size:12px; font-family:verdana; width:500px;" maxlength="15000" cols="80" rows="20"></textarea></td>
</tr></table>
<table width="100%"><tr><td align="center" width="100%">
<font size="2" face="arial"><em>After writing your letter, double check your information, then click the check box below and press "SEND."</font><br />
<!-- RECAPTCHA BOX -->
<div class="g-recaptcha" data-sitekey="MY PUBLIC KEY IS HERE"></div>
<!-- SEND BUTTON -->
<input type="submit" value="SEND" style="height:50px; width:100px; font-size:18px; font-weight:bold; background-color:#aaffaa"></td>
</tr></table>
</form>
</td></tr></table>

------------------------------------
sendemail.php is as follows
------------------------------------
<?php
    function post_captcha($user_response) {
        $fields_string = '';
        $fields = array(
            'secret' => 'MY SECRET KEY IS HERE',
            'response' => $user_response
        );
        foreach($fields as $key=>$value)
        $fields_string .= $key . '=' . $value . '&';
        $fields_string = rtrim($fields_string, '&');

        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, 'https://www.google.com/recaptcha/api/siteverify');
        curl_setopt($ch, CURLOPT_POST, count($fields));
        curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, True);

        $result = curl_exec($ch);
        curl_close($ch);

        return json_decode($result, true);
    }

    // Call the function post_captcha
    $res = post_captcha($_POST['g-recaptcha-response']);

    if (!$res['success']) {
        // What happens when the CAPTCHA wasn't checked
        echo '<p>Please go back and make sure you check the security CAPTCHA box.</p><br>';
    } else {
        // If CAPTCHA is successfully completed...

        // Paste mail function or whatever else you want to happen here!
        echo '<br><p>CAPTCHA was completed successfully!</p><br>';
    }
?>

Why will recaptcha not recognize when I check the box?

rik.depeut...@gmail.com

unread,
Feb 17, 2018, 12:03:56 AM2/17/18
to reCAPTCHA
Hi Christopher,

I'm currently in the same situation, we used to have V1, now upgrading to V2, but whenever I check the box it simply doesn't check it, therefor I never got a proper response.
Can't find anything online that would help the problem, so I'm hoping on you, did you manage to find what the problem was?

Thanks a bunch
Reply all
Reply to author
Forward
0 new messages