Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

     <!DOCTYPE>
<html>
<head >
    <title></title>
    <script src='https://www.google.com/recaptcha/api.js'></script>
    <script type="text/javascript">
        function get_action() {
            var v = grecaptcha.getResponse();
            console.log("Resp" + v );
            if (v == '') {
                document.getElementById('captcha').innerHTML = "You can't leave Captcha Code empty";
                return false;
            }
            else {
                document.getElementById('captcha').innerHTML = "Captcha completed";
                return true;
            }
        }
    </script>
</head>
<body>
    <form id="form1" onsubmit="return get_action();">
    <div>
    <div class="g-recaptcha" data-sitekey="6LdNIlAUAAAAADS_uVMUayu5Z8C0tw_jspdntbYl"></div>
    </div>
   <input type="submit" value="Button" />
   
    <div id="captcha"></div>
    </form>
</body>
</html>

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?:

like image 770
jeirueda Avatar asked Mar 31 '18 21:03

jeirueda


People also ask

How do I fix reCAPTCHA verification failed?

Help for reCAPTCHA usersMake sure your browser is fully updated (see minimum browser requirements) Check that JavaScript is enabled in your browser. Try disabling plugins that might conflict with reCAPTCHA.

Does reCAPTCHA v2 still work?

In short, yes they can. While reCAPTCHA v2 and v3 can help limit simple bot traffic, both versions come with several problems: User experience suffers, as human users hate the image/audio recognition challenges.

How do I reset reCAPTCHA v2?

For reCaptcha v2, use: grecaptcha. reset();


1 Answers

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"}
}
like image 147
TheKronnY Avatar answered Oct 11 '22 14:10

TheKronnY