reCAPTCHA working on one site, but not the other

373 views
Skip to first unread message

Robyn L

unread,
Dec 25, 2014, 12:10:17 PM12/25/14
to reca...@googlegroups.com
I am working on two websites, but reCAPTCHA is not working on one of them. Here are two test sites. One works and one doesn't. Any ideas how to fix this???

I've checked and double checked everything and I can't see why one would work and the other not. I've used test code from Google, so the problem is not my code:

kh99

unread,
Dec 25, 2014, 12:55:05 PM12/25/14
to reca...@googlegroups.com
Are you sure you're using the right keys for each domain? 

Maybe add something like this to the server side code (the first three lines exist already):

if ($resp != null && $resp->success) {
   echo
"You got it!";
 
}
else
{
   echo
"Error<br/><pre>" . print_r($resp, true) . "</pre>";
}


then you can see the returned errors.

Robyn L

unread,
Dec 25, 2014, 1:36:46 PM12/25/14
to reca...@googlegroups.com
The following error appears when that codes is added:

ReCaptchaResponse Object
(
    [success] => 
    [errorCodes] => 
)

The site key and secret key are definitely correct. I've checked and rechecked them.

kh99

unread,
Dec 25, 2014, 3:07:34 PM12/25/14
to reca...@googlegroups.com
Hmm..unfortunately that doesn't tell us much. Hopefully someone else will have an idea.

jelli

unread,
Jan 11, 2015, 9:49:40 PM1/11/15
to reca...@googlegroups.com, robyn.l...@gmail.com
Are those two sites hosted by different companies? I had a similar problem with the files provided by google. The solution was to use another method to get the response data, using curl. (I guess one hoster didn't support a prequisite for the given code.)

With a little help from http://www.9lessons.info/2014/12/google-new-recaptcha-using-php-are-you.html I got it to work, looking like this (just insert keys at the beginning). It might work for you too, if you hoster(s) provide curl.

<html>
<head><title>reCAPTCHA Example</title>
<script type="text/javascript" src="https://www.google.com/recaptcha/api.js?hl=
<?php echo $lang;?>">
</script>
</head>
<body>
   
<?php

// Verfiy Google Recaptcha v2 "NoCaptcha" with curl in php

// Insert keys
    $siteKey
= "";
    $secret
= "";


// Get Verfication from Google with curl

// Curl settings
function getCurlData($url)
{
    $curl
= curl_init();
    curl_setopt
($curl, CURLOPT_URL, $url);
    curl_setopt
($curl, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt
($curl, CURLOPT_TIMEOUT, 10);
    curl_setopt
($curl, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.16) Gecko/20110319 Firefox/3.6.16");
    $curlData
= curl_exec($curl);
    curl_close
($curl);
   
return $curlData;
}

// Get Google Response
if($_SERVER["REQUEST_METHOD"] == "POST")
{
    $recaptcha
=$_POST['g-recaptcha-response'];
   
if(!empty($recaptcha))
   
{
        $google_url
="https://www.google.com/recaptcha/api/siteverify";
        $ip
=$_SERVER['REMOTE_ADDR'];
        $url
=$google_url."?secret=".$secret."&response=".$recaptcha."&remoteip=".$ip;
        $res
=getCurlData($url);
        $res
= json_decode($res, true);
   
}
}


// Check/Use the response

if($res['success'])
   
{
    echo
"You got it!";
   
}
?>

<form action="?" method="post">
<div class="g-recaptcha" data-sitekey="
<?php echo $siteKey;?>"></div>
<br/>
<input type="submit" value="submit" />
</form>

</body>
</html>



Reply all
Reply to author
Forward
0 new messages