最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Increase ReCaptcha expiration time? - Stack Overflow

programmeradmin5浏览0评论

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=".js?onload=callback&render=explicit" async defer></script>

But it is not working.

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./recaptcha/api.js?onload=callback&render=explicit" async defer></script>

But it is not working.

Share Improve this question asked Jun 29, 2017 at 9:01 RenuRenu 1191 gold badge1 silver badge10 bronze badges 4
  • 1 Taken from the documentation Optional. The name of your callback function to be executed when the recaptcha response expires and the user needs to solve a new CAPTCHA. based on this I'd imagine it'd have to be 'expCallback' (a string) instead of a reference to the function – George Commented Jun 29, 2017 at 9:04
  • But i need to increase the expiration time, not to refresh the captacha again to resolve.Is there anyway to solve this problem?? – Renu Commented Jun 29, 2017 at 9:09
  • 2 From the documentation, it doesn’t look like it. And I doubt it would be a good idea on Google’s end to make this possible - because that might have implications on how successful people will be in trying to crack this CAPTCHA using automated tools, or sth. like that. – C3roe Commented Jun 29, 2017 at 9:14
  • See my answer for a server sided verification. If successful, store a time in a session and dont print out recaptcha, should be as easy as that. – Xorifelse Commented Jun 29, 2017 at 12:14
Add a ment  | 

2 Answers 2

Reset to default 11

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.

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

Best Solution

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

<script src="https://www.google./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>
发布评论

评论列表(0)

  1. 暂无评论