2015-11-04 935 views
0

我正在将NoCaptcha整合到网站,并且希望自己捕获失败的验证码。不幸的是,如果没有正确解决,“图片选择”验证码将立即重新加载。noCaptcha:防止自动重新加载以捕获失败的尝试

因此,如果像“挑选所有显示咖啡的图像”这样的挑战,并且用户没有正确选择所有相应的图像,挑战会立即重新加载。但我希望无论如何都要发布数据(和表单),并自行检查Captcha的正确性。

下面是它应该如何工作的一个简约例子。我相信,如果Captcha不会立即重新加载,它就会奏效。

<?php 
    require_once('recaptchalib.php'); 
    $publickey = "-----"; 
    $privatekey = "-----"; 
    try{ 
     if(isset($_POST['g-recaptcha-response'])){ 
      $captcha=$_POST['g-recaptcha-response']; 
      if(!$captcha){ exit; } 
      $response=file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=".$privatekey."&response=".$captcha."&remoteip=".$_SERVER['REMOTE_ADDR']); 
      if($response.success==false){ 
       // Do something 
      } else { 
       // Do something else 
      } 
     } 
     else 
     { 
      ?> 
      <html lang="en"> 
      <head> 
       <meta charset="utf-8" /> 
       <script src='https://www.google.com/recaptcha/api.js'></script> 
      </head> 
      <body> 
       <form method="post" action="thisfile.php"> 
        <div class="g-recaptcha" data-sitekey="<?php echo $publickey; ?>"></div> 
        <input type="submit" value="Absenden" /> 
       </form> 
      </body> 
      </html> 
      <?php 
     } 

    } catch (Exception $e) { 
     error_log($e->getMessage()); 
    } 
?> 

您是否知道防止自动重新加载的方法?

谢谢!

回答

0

您应该在reCaptcha后知道operations。 Google reCaptcha API(https://www.google.com/recaptcha/api.js)为reCaptcha操作完成所有工作;允许没有网站所有者交互(网站验证除外)与其reCaptcha。

因此,您尝试prevent reCaptcha auto-reloading或类似的操作是否会破坏其操作或导致其对最终用户的不当行为。

+0

谢谢你的回答!我知道API旨在处理所有事情。但有时不希望别人为你做所有的工作;) – coroner

+0

@coroner,如果你非常想干预谷歌事务,请阅读[我的答案](http://stackoverflow.com/a/32627606/1230477)到其他问题。 –

+0

伟大的事情!非常感谢你!我会看看这个:) – coroner