Skip to content Skip to sidebar Skip to footer

Using Google Recaptcha Always Shows 'incorrect-captcha-sol'

I'm trying to use Google reCaptcha on my website and after following several tutorials, I'm using as follow on my HTML page:

Solution 1:

The code I used for my recaptcha is as follows:

This goes in the header:

<scriptsrc='https://www.google.com/recaptcha/api.js'></script>

This goes where you want the actual recaptcha to be:

<divclass="g-recaptcha"data-sitekey="PUBLIC_KEY_HERE"></div>

You can add this to the div to change the theme: data-theme="theme"

And this is the PHP script:

if(isset($_POST['g-recaptcha-response']))
$captcha=$_POST['g-recaptcha-response'];
if(!$captcha){
    //Captcha hasn't been checked
}
$response=json_decode(file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=SECRET_KEY_HERE&response=".$captcha."&remoteip=".$_SERVER['REMOTE_ADDR']), true);
if($response['success'] == false){
    //Captcha incorrect
}
else {
    //Success code here
}

Solution 2:

From what I can see you do not have an else option after you check the answer. You check if its wrong but there is nothing to tell it what to do if the user got it right. Try adding something like this:

if (!$resp->is_valid) {
    die ("The reCAPTCHA wasn't entered correctly. Go back and try it again." . "(reCAPTCHA said: " . $resp->error . ")");
}
else {
    //Code for success here
}

Solution 3:

I use Google New reCaptcha

https://github.com/google/recaptcha Official Code

It is StandAlone package. It works with php great.

after failed captcha i use jquery code to reload capctha

grecaptcha.reset();

because recapctha response expire after validation and captcha does not reload so it will send expired response again and again until you don't reload page to get new Captcha code.

Validation code

require('/path/to/recaptcha/autoload.php');

$recaptcha = new \ReCaptcha\ReCaptcha($secret);
$resp = $recaptcha->verify($gRecaptchaResponse, $remoteIp);
if ($resp->isSuccess()) {
} else { $errors = $resp->getErrorCodes();
foreach ($errorsas$code) {
echo"<div class=\"alert alert-danger\">$code</div>";
}
echo"<p><strong>Note:</strong> Error code <tt>missing-input-response</tt> may mean the user just didn't complete the reCAPTCHA.</p>";
}

Post a Comment for "Using Google Recaptcha Always Shows 'incorrect-captcha-sol'"