简体   繁体   English

与验证码的PHP联系表:“反垃圾邮件检查失败”

[英]PHP contact form with Captcha: “failed the anti-spam check”

I'm using a Contract form from HTML Contract Form Guide in my website. 我在网站上使用HTML合同表格指南中的合同表格。 In testing, I am running my website from my computer using apache and PHP v5.5. 在测试中,我正在使用apache和PHP v5.5从我的计算机上运行我的网站。 Everything seems to work well on my testing server and I can fill out the form, click submit, and land on the "success page". 一切似乎都可以在我的测试服务器上正常运行,我可以填写表格,单击提交,然后进入“成功页面”。 When I upload my site to my hosting service and try to use the contact form, the captcha does not accept my input and returns the message, "failed the anti-spam check". 当我将网站上传到托管服务并尝试使用联系表时,验证码不接受我的输入,并返回消息“反垃圾邮件检查失败”。 My hosting service is running PHP v5.3. 我的托管服务正在运行PHP v5.3。 I'm not sure what's changing and why my form no longer works when I upload it. 我不确定发生了什么变化,为什么我上载表单后不再起作用。 Oh, I am also learning PHP on the fly so I might not fully comprehend what I am being asked so it might take me a little longer to give an accurate reply. 哦,我也在实时学习PHP,所以我可能无法完全理解所要询问的内容,因此可能需要一点时间才能给出准确的答复。

* This issue was solved. *此问题已解决。 I ended up contacting fatcow which is my hosting company. 我最终联系了我的托管公司Fatcow。 This is their response "I have set the session.save_path in your 'PHP Scripting' and I have increased the memory limit from 32 MB to 128 MB for your PHP scripts." 这是他们的回答“我已经在您的'PHP脚本'中设置了session.save_path,并且我将PHP脚本的内存限制从32 MB增加到128 MB。 I guess it was a server side issue. 我想这是服务器端的问题。 I guess I've narrowed it down and when I run to a similar issue I can also assume it is a server side issue. 我想我已经缩小了范围,当遇到类似问题时,我也可以认为这是服务器端问题。 Hope anyone with a similar issue can use this post and decide what to do accordingly. 希望有类似问题的任何人都可以使用此帖子,并决定相应地做什么。

I ran var_dump() on $_SESSION['FGCF_Captcha_Answer'] and $user_answer and both values were equal. 我在$_SESSION['FGCF_Captcha_Answer']$user_answer上运行了var_dump() ,两个值相等。 This is what I got: 这就是我得到的:

string 'c85757e710d687d24c0b044812d5ee05' (length=32) 字符串'c85757e710d687d24c0b044812d5ee05'(长度= 32)

string 'c85757e710d687d24c0b044812d5ee05' (length=32) 字符串'c85757e710d687d24c0b044812d5ee05'(长度= 32)

I am also hosting from a fatcow server and have contacted them to see if they know anything about this issue with reCAPTCHA on their server. 我也从Fatcow服务器托管,并已与他们联系,以查看他们是否对服务器上的reCAPTCHA有关此问题有任何了解。 Just awaiting their reply. 只是在等待他们的答复。 Is it possible that the server I'm running on could experience these things, maybe not a programming question but like I stated above, on my own computer running with apache the form works fine and the only problem I'm having on fatcow is not the entire form, just reCAPTCHA 我正在运行的服务器是否可能会遇到这些问题,也许不是编程问题,但如上所述,在我自己的以apache运行的计算机上,表单运行正常,而我在fatcow上遇到的唯一问题不是整个表格,只需reCAPTCHA

Here is the captcha code, if anything else is needed please let me know: 这是验证码,如果还有其他需要,请告诉我:

<?PHP
    class FGSimpleCaptcha extends FG_CaptchaHandler
    {
var $error_str;
var $captcha_varname;
var $uniquekey;

function FGSimpleCaptcha($captcha_var_name)
{
    $this->captcha_varname=$captcha_var_name;
    $this->uniquekey='KHJhsjsy65HGbsmnd';
}

/*Add more simple questions here.*/
function GetSimpleCaptcha()
{
    $arrQuestions = array(
    "What color is the sky? "=>"blue",
    "What is 1+1=" => "2",
    "What is the color of grass?"=>"green",
    "Are you a robot? "=>"no",
    "Are you human?"=>"yes");

    $question = array_rand($arrQuestions);
    $answer = $arrQuestions[$question];

    $_SESSION['FGCF_Captcha_Answer'] = $this->Md5CaptchaAnswer($answer);

    return $question;
}

function SetFormKey($key)
{
    $this->uniquekey = $key;
}
function GetKey()
{
    return $this->uniquekey;
}
function Validate()
{
    $ret=false;
    if(empty($_POST[$this->captcha_varname]))
    {
        $this->error_str = "Please answer the anti-spam question";
        $ret = false;
    }
    else
    {

        $scaptcha = trim($_POST[$this->captcha_varname]);

        $scaptcha = strtolower($scaptcha);

        $user_answer = $this->Md5CaptchaAnswer($scaptcha);

        if($user_answer != $_SESSION['FGCF_Captcha_Answer'])
        {
            $this->error_str = "Failed the anti-spam check!";
            $ret = false;
        }
        else
        {
            $ret = true;
        }
    }//else
    return $ret;
}
function Md5CaptchaAnswer($answer)
{
    return md5($this->GetKey().$answer);
}
function GetError()
{
    return $this->error_str;
}
}
?>

Here is partial code for the form: 这是表单的部分代码:

    class FGContactForm
{
var $receipients;
var $errors;
var $error_message;
var $name;
var $email;
var $message;
var $from_address;
var $form_random_key;
var $conditional_field;
var $arr_conditional_receipients;
var $fileupload_fields;
var $captcha_handler;

var $mailer;

function FGContactForm()
{
    $this->receipients = array();
    $this->errors = array();
    $this->form_random_key = 'HTgsjhartag';
    $this->conditional_field='';
    $this->arr_conditional_receipients=array();
    $this->fileupload_fields=array();

    $this->mailer = new PHPMailer();
    $this->mailer->CharSet = 'utf-8';
}

function EnableCaptcha($captcha_handler)
{
    $this->captcha_handler = $captcha_handler;
    session_start();
}

function AddRecipient($email,$name="")
{
    $this->mailer->AddAddress($email,$name);
}

function SetFromAddress($from)
{
    $this->from_address = $from;
}
function SetFormRandomKey($key)
{
    $this->form_random_key = $key;
}
function GetSpamTrapInputName()
{
    return 'sp'.md5('KHGdnbvsgst'.$this->GetKey());
}
function SafeDisplay($value_name)
{
    if(empty($_POST[$value_name]))
    {
        return'';
    }
    return htmlentities($_POST[$value_name]);
}
function GetFormIDInputName()
{
    $rand = md5('TygshRt'.$this->GetKey());

    $rand = substr($rand,0,20);
    return 'id'.$rand;
}


function GetFormIDInputValue()
{
    return md5('jhgahTsajhg'.$this->GetKey());
}

function SetConditionalField($field)
{
    $this->conditional_field = $field;
}
function AddConditionalReceipent($value,$email)
{
    $this->arr_conditional_receipients[$value] =  $email;
}

function AddFileUploadField($file_field_name,$accepted_types,$max_size)
{

    $this->fileupload_fields[] =
        array("name"=>$file_field_name,
        "file_types"=>$accepted_types,
        "maxsize"=>$max_size);
}

function ProcessForm()
{
    if(!isset($_POST['submitted']))
    {
       return false;
    }
    if(!$this->Validate())
    {
        $this->error_message = implode('<br/>',$this->errors);
        return false;
    }
    $this->CollectData();

    $ret = $this->SendFormSubmission();

    return $ret;
}

function RedirectToURL($url)
{
    header("Location: $url");/* Redirect browser */

    /* Make sure that code below does not get executed when we redirect. */
    exit;
}

function GetErrorMessage()
{
    return $this->error_message;
}
function GetSelfScript()
{
    return htmlentities($_SERVER['PHP_SELF']);
}

function GetName()
{
    return $this->name;
}
function GetEmail()
{
    return $this->email;
}
function GetMessage()
{
    return htmlentities($this->message,ENT_QUOTES,"UTF-8");
}

This issue was solved. 这个问题解决了。 I ended up contacting fatcow which is my hosting company. 我最终联系了我的托管公司Fatcow。 This is their response "I have set the session.save_path in your 'PHP Scripting' and I have increased the memory limit from 32 MB to 128 MB for your PHP scripts." 这是他们的回答“我已经在您的'PHP脚本'中设置了session.save_path,并且我将PHP脚本的内存限制从32 MB增加到128 MB。 I guess it was a server side issue. 我想这是服务器端的问题。 With some help I was able to narrow it down and when I run to a similar issue I can also assume it is a server side issue. 在一些帮助下,我能够缩小范围,当我遇到类似问题时,我也可以认为这是服务器端问题。 Hope anyone with a similar issue can use this post and decide what to do accordingly. 希望有类似问题的任何人都可以使用此帖子,并决定相应地做什么。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM