I currently implementing the reCaptcha for an form with HTML and PHP. The client-side solution works without any problems. But the server side fails with the validation.
So here is my server side code:
$data = array(
"secret" => "MY_SECRET_KEY",
"response" => $captcha_response,
"remoteip" => $_SERVER['REMOTE_ADDR']
);
$opts = [
"http" => [
"method" => "POST",
"header" => "Accept-language: en",
"content" => http_build_query($data)
]
];
$context = stream_context_create($opts);
$data = json_decode(file_get_contents('https://www.google.com/recaptcha/api/siteverify', false, $context), true);
So now when I dump the result I get the following output:
array(4) {
["success"]=>
bool(false)
["challenge_ts"]=>
string(20) "2017-06-22T13:14:50Z"
["hostname"]=>
string(9) "localhost"
["error-codes"]=>
array(1) {
[0]=>
string(12) "invalid-keys"
}
}
I'm sure that the response code will completly send to the PHP script.
I also searched in the API docs, but only find these error codes and nothing matches with invalid-keys
.
What did I wrong?
If you are using reCAPTCHA on your site and you see the error 'ERROR for site owner: Invalid domain for site key', this means your site key is no longer valid. Also, your website url must match exactly what is included in the site key settings. Subdomains don't need to be added separately.
If you're seeing this reCAPTCHA challenge, your browser environment doesn't support the reCAPTCHA checkbox widget. There are a few steps you can take to improve your experience: Make sure your browser is fully updated (see minimum browser requirements) Check that JavaScript is enabled in your browser.
So dumb. I took the secret key from the wrong project from the admin console. The wrong project not white listed localhost
, which I needed. Also the public-site-key and secret-key were mismatched (but both individually valid).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With