douzuo0711 2016-03-20 21:01
浏览 22

有php头功能的麻烦

For some reason unknown to me my php header function will not re-direct my script to a new page. I am aware that no output can be on sent to the screen before the function call but, my script is still not working despite me not seeing any output to the screen. My code is below. This code executes several if blocks of code then redirects the user to the apporiate page.

here is the code:

    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.' 

'. $_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();
}

Here is the test "Test_Input.php" script that is called by the above code.

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;
        }
    }
 }

Here is the "Check_Password.php" script called by the above code:

    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条回答 默认 最新

  • 普通网友 2017-04-29 11:20
    关注

    you can always use html header redirect is what I use when PHP header location is not responding due to some hard to find bug. http://example.com/" /> You have to echo it out echo the html meta tag like you would normally echo html tags or you can neatly place it outside delimiters

    评论

报告相同问题?

悬赏问题

  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画