0

如何在登录表单中添加 Recaptcha?我的代码是:

<form action="<?=$PHP_SELF?>" method="post">
        <input type=hidden name=menu value=login>
        User Id: <br><input class="inp" type="text" name="uNev"><br>
        Password: <br><input class="inp" type="password" name="uJelszo">
                  <p align="center"><input class="inp" type="submit" name="uLogin" value="Log-In" id="button">
    </form>

我会尝试recaptcha-php-1.11但不知道该怎么做,请帮助我。

4

2 回答 2

3

您可以为此使用谷歌验证码。谷歌验证码最适合安全观点。它还提供音频验证码。它非常易于使用。 http://www.google.com/recaptcha/whyrecaptcha

于 2013-09-17T12:04:48.557 回答
0

1) 从这里下载 recaptcha 库https://code.google.com/p/recaptcha/downloads/detail?name=recaptcha-php-1.11.zip&can=2&q=label%3Aphplib-Latest

2) 解压并将文件复制recaptchalib.php到表单文件所在的目录中。

3)在这里注册recaptcha http://www.google.com/recaptcha/whyrecaptcha

4)复制公钥并将其粘贴到您的表单文件中的正确位置,该文​​件必须如下所示:

<html>
<body> <!-- the body tag is required or the CAPTCHA may not show on some browsers -->
  <!-- your HTML content -->

  <form method="post" action="verify.php">
    Name:<input type="text" name="name"> <br>
    Email: <input type="email" name="email">
    <?php
      require_once('recaptchalib.php');
      $publickey = "your public key here"; // you got this from the signup page
      echo recaptcha_get_html($publickey);
    ?>
    <input type="submit" />
  </form>

  <!-- more of your HTML content -->
</body>
</html>

5) 然后创建另一个文件 verify.php,它也必须与您的表单和 recaptchalib.php 文件一起存在。

 <?php
  require_once('recaptchalib.php');
  $privatekey = "your private key here";
  $resp = recaptcha_check_answer ($privatekey,
                                $_SERVER["REMOTE_ADDR"],
                                $_POST["recaptcha_challenge_field"],
                                $_POST["recaptcha_response_field"]);

  if (!$resp->is_valid) {
    // What happens when the CAPTCHA was entered incorrectly
    die ("The reCAPTCHA wasn't entered correctly. Go back and try it again." .
         "(reCAPTCHA said: " . $resp->error . ")");
  } else {
    // Your code here to handle a successful verification
    echo "Success!";
  }
  ?>

6)从您获得公钥的页面中,现在复制私钥并将其粘贴到verify.php文件中的正确位置。

于 2013-09-17T12:47:18.797 回答