微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

php – ReCaptcha一直说我是机器人,不会成功吗?

我在我的网站上使用旧的ReCaptcha,但只是升级到新的ReCaptcha我有3-4个不同的教程,但它一直失败并给出失败错误.

HTML

<form method="POST" action="/Feedback_sent/" enctype="multipart/form-data">
<table border="0" width="100%" cellpadding="4" cellspacing="4" height="67">
    <tr>
        <td width="30%" height="30">Name</td>
        <td width="70%" height="30">
            <p><input type="text" name="name" size="41"></p>
        </td>
    </tr>
    <tr>
        <td valign="top" width="30%" height="27">Feedback</td>
        <td width="70%" height="27">
        <textarea rows="8" name="Feedback" cols="57"></textarea></td>
    </tr>   
    <tr>
        <td valign="top" width="30%" height="27"></td>
        <td width="70%" height="27">
        <div class="g-recaptcha" data-sitekey="My_Key"></div>
        </td>
    </tr>
    <tr>
        <td width="100%" colspan="2">
        <p align="center"><input type="submit" value="Submit" name="B1"></td>
    </tr>
</table>


</form>

PHP

$secret="---my key---";
    $response=$_POST["g-recaptcha-response"];
    $verify=file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret={$secret}&response={$response}");
    $captcha_success=json_decode($verify);

    if ($captcha_success->success==false) {
        echo "<p>You are a bot! Go away!</p>";
    }
    else if ($captcha_success->success==true) {
            echo "<p>You are not not a bot!</p>";
    }
步骤1:

您需要创建公钥和私钥here.

第2步:

包含this库以处理服务器上的信息.

代码

<?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>

这将说明成功或失败取决于输入.

原文地址:https://www.jb51.cc/php/138321.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐