简体   繁体   中英

Increase ReCaptcha expiration time?

How to increase the google ReCaptcha expiration time? I have tried below one,

  <script>
   var callback = function() {
      grecaptcha.render('id-of-render-element', {
         'sitekey': 'your-site-key',
         'expired-callback': expCallback
       });
   };
   var expCallback = function() {
      grecaptcha.reset();
   };
</script>
    <div id="id-of-render-element"></div>
<script src="https://www.google.com/recaptcha/api.js?onload=callback&render=explicit" async defer></script>

But it is not working.

This has worked for me on both Invisible and the Checkbox versions. I understand you want to "increase" the time, however that is not an option Google offers. I simply reboot the box every 5 min.

setInterval(function(){ grecaptcha.reset(); }, 5 * 60 * 1000 ); 
// just reset every 5 min

Also, setting the "Advanced" box slider in your Google Developer Console to "least restrictions" seems to help.

Keep in mind with the new "Invisible" Recapcha you may not need to reset or extend the time unless you have additional AJAX validation. I have noticed that when I use the new "invisible" method that the box stays good forever if I only trigger it when the form is validated first.

QED A better solution to the problem might then be simple to use this https://developers.google.com/recaptcha/docs/invisible#auto_render

Best Solution

<input type='hidden' name='recaptcha_token' id='recaptcha_token'>

<script src="https://www.google.com/recaptcha/api.js?render={{ env("GOOGLE_CAPTCHA_PUBLIC_KEY") }}"></script>

<script>
    setInterval(function () { 
        grecaptcha.ready(function() {
            grecaptcha.execute('{{ env("GOOGLE_CAPTCHA_PUBLIC_KEY") }}')    
            .then(function(token) {
                document.getElementById("recaptcha_token").value = token;
            }); 
        });
    }, 30 * 1000);
</script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM