遇到php标头函数问题

时间:2016-03-20 21:01:08

标签: php function header web-application-design

由于某些原因我不知道我的php标头函数不会将我的脚本重定向到新页面。我知道在函数调用之前没有输出可以发送到屏幕但是,尽管我没有看到任何输出到屏幕,但我的脚本仍然无法正常工作。我的代码如下。此代码执行几个if代码块,然后将用户重定向到apporiate页面。

这是代码:

    session_start();
    require_once('Test_Input.php');
    if(!isset($_SESSION['Form_First_Name']) ||       !isset($_SESSION['Form_Last_Name']) || !isset($_SESSION['Form_Email']) || !isset($_SESSION['Form_Message']))
{
    $_SESSION['Form_First_Name'] = '';
    $_SESSION['Form_Last_Nameorm'] = '';
    $_SESSION['Form_Email'] = '';
    $_SESSION['Form_Message'] = '';
} 
if(isset($_POST['Clear']) && $_POST['Clear'] == 'clear')
{
    $_SESSION['Form_First_Name'] = '';
    $_SESSION['Form_Last_Nameorm'] = '';
    $_SESSION['Form_Email'] = '';
    $_SESSION['Form_Message'] = '';
    unset($_SESSION['name_Switch']);
    unset($_SESSION['Form_Email_Switch']);
    //header('location:Contact_Form.php');
}
$response = $_POST['Response'];
$image_request = $_POST['DB_Response'];
$first_name = $_SESSION['Form_First_Name'] = $_POST['First_Name'];
$last_name = $_SESSION['Form_Last_Name'] = $_POST['Last_Name'];
$email = $_SESSION['Form_Email'] = $_POST['Email'];
$_SESSION['Form_Message'] = $_POST['Message'];
$first_name_result = Test_Input::name_validation($first_name);
var_dump($first_name_result);
$last_name_result = Test_Input::name_validation($last_name);
$email_result = Test_Input::email_validation($email);
if(!$first_name_result || !$last_name_result )
{
    $_SESSION['Name_Switch'] = false;
    header('location:Contact_Form.php');
    exit();
}
if (!$email_result)
{
    $_SESSION['Form_Email_Switch'] = false;
    header('location:Contact_Form.php');
    exit();
}
if($response != $image_request)
{
    unset($_SESSION['Email_Switch']);
    header('location:Contact_Form.php');
    exit();
}

else 
{
    global $first_name;
    global $last_name;
    global $email;
    $message = 'FROM: '.$first_name.' '.$last_name.' \n\n'. $_POST['Message'];
    $to = 'admin@showlove-productions.com';
    $subject = 'Show Love Production Contact Form';
    $headers = $email;
    mail($to, $subject, $message, $headers);
    $_SESSION['Email_Switch'] = true;
    unset($_SESSION['Form_First_Name']);
    unset($_SESSION['Form_Last_Name']);
    unset($_SESSION['Form_Email']);
    unset($_SESSION['Form_Message']);
    header('location:Contact_Form.php');
    exit();
}

这是测试" Test_Input.php"上面代码调用的脚本。

require_once('Check_Password.php');
class Test_Input extends Check_Password
{
    public static function test_input_info($data) 
    {
        $data = trim($data);
        $data = stripslashes($data);
        $data = htmlspecialchars($data);
        return $data;
    }

    public static function name_validation($data)
    {
        if (!preg_match("/^[a-zA-Z]*$/",$data) || empty($data))
        {
            return false;
        }
        else
        {
            return true;
        }
    }

    public static function  user_name_validation($data)
    {
        if (!preg_match("/^[a-zA-Z0-9\_\-]*$/",$data))
        {
                return false;
        }   

        else
        {
            return true;
        }
    }
    public static function email_validation($data)
    {
        if (!filter_var($data, FILTER_VALIDATE_EMAIL)) 
        {
            return false;
        }
        else
        {
            return true;
        }
    }
    public static function password_validation($password, $conf_password)
    {
        if($password == $conf_password)
        {
            return 0;
        }

        else if (empty($password) || empty($conf_password))
        {
            return 1;
        }

        else
        {
            return -1;
        }   
    }
    public static function  music_prod_validation($data)
    {
        if (!preg_match("/^[a-zA-Z0-9]+[a-zA-Z0-9_\_\- ]*$/",$data))
        {
                return false;
        }   

        else
        {
            return true;
        }
    }
 }

这是" Check_Password.php"上面代码调用的脚本:

    class Check_Password
{
    public function check_pass($password, $conf_password)
    {
        if($password == $conf_password)
        {
            return 0;
        }
        else if (empty($password) || empty($conf_password))
        {
            return 1;
        }
        else
        {
            return -1;
            }
        }
    }

1 个答案:

答案 0 :(得分:-1)

你总是可以使用html标题重定向是我在PHP标题位置没有响应时使用的,因为一些很难找到的bug。 http://example.com/" /> 你必须回应它回显html元标记,就像你通常会回显html标签,或者你可以整齐地将它放在分隔符之外