我是这里的新手,所以希望我在正确的地方发帖!我对代码只有最基本的了解。技术问题,所以我希望我能解释这个....
我正试图在我的网站上的表单上实现验证码,以阻止机器人攻击它。我用这个:
https://developers.google.com/recaptcha/docs/php我为客户端创建了一个测试php文件,并成功地在表单上实现了小部件。
我还为服务器端创建了一个verify.php文件,但是我不清楚在verify.php文件中输入什么,其中指令(按照上面的链接)说在粗体:
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**
说明如下,但我不明白在哪里输入什么。
在上面的代码中:Recaptcha_check_answer返回一个对象,表示用户是否成功完成挑战。如果$resp->is_valid为true,则验证码挑战已正确完成,您应该继续进行表单处理。
如果$resp->is_valid为false,则用户未能提供正确的captcha文本,您应该重新显示表单以允许他们再次尝试。在这种情况下,$resp->error将是一个错误代码,可以提供给recaptcha_get_html。传递错误代码会使reCAPTCHA控件显示一条消息,说明用户输入的文本不正确,应该再试一次。
任何帮助都非常感谢!
非常感谢。div标记
//当CAPTCHA输入不正确时会发生什么 ->在此情况下,应该将用户重定向到表单页面,并提示他没有正确填写CAPTCHA。
//你的代码在这里处理一个成功的验证 ->在这个下,正常提交你的联系表单
这是一个在我的网站上工作的代码:
$publickey = "YOUR PUBLIC KEY HERE";
$privatekey = "YOUR PRIVATE KEY";
$resp = null;
$resp = recaptcha_check_answer ($privatekey,
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]);
if($resp->is_valid){
// under this, submit your contact form normally.
}
else {
header("Location: page_where_the_user_was.php?error=1");
die();
}
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 "Login succesfull"; }
这包括重定向到需要再次填写验证码的页面。希望对你有所帮助。
if (!$resp->is_valid) {
**// What happens when the CAPTCHA was entered incorrectly**
header('Location: index.php');
**// Or test.php, I don't know the name of your page
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 "Login succesfull"; }