Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

reCaptcha: error code "invalid-keys"

Tags:

php

recaptcha

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?

like image 858
Julian Schmuckli Avatar asked Jun 22 '17 13:06

Julian Schmuckli


People also ask

Why does reCAPTCHA say invalid domain for site key?

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.

Why is my reCAPTCHA verification failed?

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.


1 Answers

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

like image 135
Julian Schmuckli Avatar answered Sep 19 '22 10:09

Julian Schmuckli