I wanted to integrate reCaptcha in a website and bit of confused, about it's working.
Here's how I configured:
Added this code in head:
<script src='https://www.google.com/recaptcha/api.js?render=SITE_KEY></script>
Used this code on page load to get reCaptcha response
<script>
grecaptcha.ready(function() {
grecaptcha.execute('SITE_KEY', {action: 'register'})
.then(function(token) {
jQuery('#recaptcha').val(token);
});
});
</script>
Use this code to verify captcha response
$secret = 'SECRET_KEY'; $verifyResponse = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret='.$secret.'&response='.$_POST['recaptcha']); $responseData = json_decode($verifyResponse); if($responseData->success){ //valid response, move forward }else{ //captcha check failed, throw an error }
It seems to work fine for me, and I'm getting 0.9 score for my requests.
Problem: Assume captcha failed for a valid user request because of any reason (like ip was used for spamming or any other google verification check failed). But the user is legitimate so:
- how do a user can prove his humanity? (like in previous checkbox version)
- if user loads registration form and go for other activities, the user came back after sometime (e.g 10 mins). When user will try to submit form, the captcha check will fail. (I tried this and got error back 'timeout-or-duplicate')
- Is there any way to reload captcha, without page reload?
Please lemme know, how to overcome those issues?