Google reCAPTCHA V2 JavaScript We detected that your site is not verifying reCAPTCHA solutions

jeirueda  picture jeirueda · Mar 31, 2018 · Viewed 13.7k times · Source

Error Message We detected that your site is not verifying reCAPTCHA solutions. This is required for the proper use of reCAPTCHA on your site. Please see our developer site for more information. I created this reCaptcha code, it works well but I don not know how can I validate it, I thought it was validating with the function grecaptcha.getResponse(); but it was not so. Apparently The recaptcha worked well on the website but I just saw in Google admin the next message: enter image description here

Requirements: 1.Do not use action="file.php" in the form, only a javascript function in the form.

May you help me Please. I would appreciate it a lot How can I validate it since I need to use a javascript function onsubmit="return get_action();" instead of action="file.php" *when I submit?:

Answer

TheKronnY picture TheKronnY · Apr 1, 2018

The grecaptcha.getResponse() function will only provide you with the user response token, which then must be validated with HTTP POST call on google reCAPTCHA server.

You could use AJAX request, to validate the token, but these validations should always be done on server side, for security reasons - JavaScript could've always been meddled with by user and tricked into believing that reCAPTCHA was successfully verified.

Google reCAPTCHA docs:

After you get the response token, you need to verify it with reCAPTCHA using the following API to ensure the token is valid.

So what you need to do is to send your reCAPTCHA secret (second key that was generated for you in reCAPTCHA admin page) and user response token (the one received from grecaptcha.getResponse() function) to reCAPTCHA API as described in reCAPTCHA docs.

In PHP, you'd do somethink like this:

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "https://www.google.com/recaptcha/api/siteverify");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query([
    'secret'   => YOUR_RECAPTCHA_SECRET,
    'response' => USER_RESPONSE_TOKEN,
]));

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$data = curl_exec($ch);

curl_close($ch);

$response = @json_decode($data);

if ($response && $response->success)
{
    // validation succeeded, user input is correct
}
else
{
    // response is invalid for some reason
    // you can find more in $data->{"error-codes"}
}