如何在登录表单中添加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 ,但不知道该怎么做,请帮助我。
答案 0 :(得分:3)
您可以使用google recaptcha进行此操作.Google验证码最适合安全观点。它还提供音频验证码。它非常易于使用。 http://www.google.com/recaptcha/whyrecaptcha
答案 1 :(得分: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)注册重新访问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
文件中的正确位置。