I integrated Googles funky ReCaptcha NoCaptcha into a simple html5 form. On localhost it is working, but testing online it always returns the error 'invalid-json'. Here is part of my code:
$secret = 'TEHSEHCRET';
$recaptcha = new \ReCaptcha\ReCaptcha($secret);
$resp = $recaptcha->verify($_POST['g-recaptcha-response'], $_SERVER['REMOTE_ADDR']);
if ($resp->isSuccess()) {
// do some
}
else {
print_r($errors = $resp->getErrorCodes());
}
Returns Array ( [0] => invalid-json )
I googled for some help but found nothing really helpful.
Since the code on- and offline is the same I am really clueless where the problem is coming from. https://developers.google.com/recaptcha/docs/verify says nothing about the error code. Guess the solution is too simple.
I had the same issue and fixed it by using cURL as request method instead POST.
the response is a json object. it should be decoded first. i am pretty new to web programming/development, but i successfully integrated google recaptcha on an asp.net test site which does nothing for now, but i'm sure it handles the json response just the way i want it to..
found another, could this help.
This solved it for me:
// Make the call to verify the response and also pass the user's IP address
If you are using reCAPTCHA PHP client library < 1.2.4 with
SocketPost
request method then you need to update to ≤ 1.2.4 or you should switch toCurlPost
because the Google server response has changed: https://github.com/google/recaptcha/issues/359