문제

I'm loading Recaptcha using this:

<script src="//www.google.com/recaptcha/api/challenge?k=key"></script>

and using AJax and PHP to validate the response:

$ch=curl_init('http://www.google.com/recaptcha/api/verify');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, array(
    'privatekey'=>'key',
    'remoteip'=>$_SERVER['REMOTE_ADDR'],
    'challenge'=>$_POST['recaptcha_challenge_field'],
    'response'=>$_POST['recaptcha_response_field']
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response=@curl_exec($ch);

if(substr($response,0,4)!='true')
    die('The verification code is incorrect.');

For some reason, if I enter the Captcha incorrectly, then re-enter it correctly, the verification always returns "false". How do I allow the user the resubmit the Recaptcha response (without reloading the image) if they entered it incorrectly the first time?

도움이 되었습니까?

해결책

You can't. The user cannot be given a second attempt at a reCaptcha challenge — if they get one wrong, they will need to attempt a different one the next time. For a web form, this should typically be implemented by redisplaying the form with an error message if the reCaptcha challenge fails, rather than forcing the user to use the "Back" button.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top