Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/282.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP似乎在使用SecurImageCaptcha时同时执行if和else_Php_If Statement_Validation_Captcha - Fatal编程技术网

PHP似乎在使用SecurImageCaptcha时同时执行if和else

PHP似乎在使用SecurImageCaptcha时同时执行if和else,php,if-statement,validation,captcha,Php,If Statement,Validation,Captcha,我正在尝试使用PHP验证码来验证网站上的联系人表单,过去几天我遇到了一个难题,表单在FF、Chrome、Safari上运行良好,但在IE上运行不正常。我在这里搜索了大量帖子,但没有找到任何似乎能解决我问题的方法,所以我希望你们中的一些专家能在这里帮我一把:)。事实上,这只是在IE上,这让我感到困惑,因为我能想到的唯一问题是会话变量,它似乎在IE中工作得很好 下面是验证我的联系人表单发送的验证码的主代码。我应该指出,验证码确实是通过邮寄发送的,因为我已经检查了标题和代码:var\u dump($s

我正在尝试使用PHP验证码来验证网站上的联系人表单,过去几天我遇到了一个难题,表单在FF、Chrome、Safari上运行良好,但在IE上运行不正常。我在这里搜索了大量帖子,但没有找到任何似乎能解决我问题的方法,所以我希望你们中的一些专家能在这里帮我一把:)。事实上,这只是在IE上,这让我感到困惑,因为我能想到的唯一问题是会话变量,它似乎在IE中工作得很好

下面是验证我的联系人表单发送的验证码的主代码。我应该指出,验证码确实是通过邮寄发送的,因为我已经检查了标题和代码:
var\u dump($securimage->check($\u post['captcha\u code'])
在验证码正确或不正确时正确返回true和false,正如您所期望的那样

主要的问题似乎是,如果验证码输入正确并且
$securimage->check($\u POST['captcha\u code'])
在IE上返回true,则执行语句
if($captcha\u result==FALSE)
,但也使用相应else中的mail()函数发送电子邮件。由于某种原因,
$formSent=2
似乎没有在mail()函数所在的else中运行。我尝试了if和else的组合,各种各样的组合都没有运气。这一定是我在某个地方的用户错误

<?php
session_start();
include('securimage/securimage.php');


        if (isset($_POST['query_form'])) {


            if ($_POST['name'] == "Your name" || $_POST['email'] == "Your E-mail" || $_POST['message'] == "Message") {
                $formSent = 1; //display the notification bar wth error.
            } 
            else {

                //validate the captcha code now.
                $securimage = new Securimage();
                //var_dump($securimage->check($_POST['captcha_code']));
                $captcha_result = $securimage->check($_POST['captcha_code']);


                //ERROR - IE runs the first if and the mail function below for some reason.
                if ($captcha_result == FALSE) {
                    $formSent = 3; //display the notification bar wth captcha error.    
                }

                else if ($captcha_result !== FALSE) {               
                    $to = 'email';
                    $subject = 'subject';
                    $message = "Name: " .  $_POST['name'] . "\r\n" . "Email: " . $_POST['email'] . "\r\n" . "Phone: " . $_POST['phone'] . "\r\n" . "Message: " . $_POST['message'] ;
                    $headers = 'From: email' . "\r\n" .
                        'Reply-To: ' . $_POST['email'] . "\r\n";


                    mail($to, $subject, $message, $headers);
                    $formSent = 2; //display the notification bar with success.     

                }
            }

        }

?>


永远不要做'if($captcha\u result==FALSE){…}否则if($captcha\u result!==FALSE){`。找到bug(这里可能是测试问题)而不是尝试voodoo。感谢回复,voodoo是我最后的努力:D.尝试将语句更改为if($captcha\u result==TRUE)使用相应的else。在所有浏览器上都可以,但IE仍然可以,它在做相同的事情-知道为什么部分if和部分else都在执行吗?很抱歉,我不知道如何执行if和else子句。这就是为什么我认为存在测试问题(延迟、双重请求等)的原因.谢谢,你的双重请求非常准确!奇怪的是,它只是IE,但现在已经解决了:)