ReCaptcha keeps saying im a bot, doesn't ever succeed?

后端 未结 1 1088
遇见更好的自我
遇见更好的自我 2020-12-12 02:46

I was using the old ReCaptcha on my site but just upgrading to the new ReCaptcha i\'ve 3-4 different tutorials but it keeps failing and giving the fail error.

HTML

相关标签:
1条回答
  • 2020-12-12 03:02

    Step 1:

    You will need to create a public and a private key here.

    Step 2:

    Include this library to process the information on the server.

    The code:

    <?php
      $public  = "yourkey";
      $private = "yourkey";
      $lang    = "en";
    
      if(isset($_POST['submit'])){
        if(array_key_exists('g-recaptcha-response', $_POST)){
          require 'path/to/recaptcha/autoload.php';
          $c = new ReCaptcha\ReCaptcha($private);
    
          $r = $c->verify(
            $_POST["g-recaptcha-response"],
            $_SERVER["REMOTE_ADDR"]
          );
    
          if($r->isSuccess()){
            echo 'success';
          } else {
            echo 'failed';
          }
        } else {
          die('client failure, enable js or update browser');
        }
      } else {
        die('form failure');
      }
    ?>
    
    <!DOCTYPE html>
    <html lang="en">
      <head>
        <title>ReCaptcha 2.0</title>
      </head>
      <body>
         <form action="<?= $_SERVER['PHP_SELF'] ?>" method="post">
          <input for="email" name="email" type="email" required>
          <input for="password" name="password" type="password" required>
          <div class="g-recaptcha" data-sitekey="<?= $public ?>"></div>
          <input type="submit" name="submit" value="Submit">
        </form>
        <script src='https://www.google.com/recaptcha/api.js?hl=<?= $lang ?>'></script>
      </body>
    </html>
    

    This will say either success or failed depending on the input.

    0 讨论(0)
提交回复
热议问题