因此,基本上,我有一个表单,提交信息到我的网站,然后我可以批准信息到我的网站上或删除它。
最近,我向站点添加了一个recaptcha检查程序,这样我就可以避免垃圾邮件发送者之类的问题,但问题是,我在同一个文件(submitinfo.php)中有提交页面的进程和布局。
由于captcha不正确(因为他们没有机会输入它),recaptcha进程会自动杀死页面,所以我认为,我不会关闭页面,我只会想出一条消息,说明captcha是不正确的,但是如上所述,当用户第一次打开页面时,他们还没有机会输入captcha,所以消息会显示,尽管他们还没有输入任何内容。
我想,如果我添加一个计数器,它只在计数器大于0的情况下显示一条消息,并且每次加载页面时都添加+1。我这样做了,但是即使在得到captcha错误的几次之后,这个消息也不会出现,我认为这是因为每次我按submit按钮时,计数器都会重置。下面是代码,这样你们就可以看到我实际做了什么:
$count
settype($count,"integer");
require_once('recaptchalib.php');
$privatekey = "My Private Captcha Key goes here";
$resp = recaptcha_check_answer ($privatekey,
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]);
// the stuff above is just the code from the captcha
if (!$resp->is_valid) {
// What happens when the CAPTCHA was entered incorrectly
if($count>0){ $errormessage = "block"; //this displays the error message if the counter is greater then 0
}
$count++;
} else{
//here it submits the info发布于 2015-01-10 10:19:59
在检查captcha之前,只需检查是否有$_POST数据即可。应该是这样的:
<?php
if ($_POST) {
// check captcha
if ($captcha_valid) {
// persist submitted form data
// redirect on success
} else {
$error = 'captcha';
}
}
?>
<!-- display form -->https://stackoverflow.com/questions/27874185
复制相似问题