2016-03-20 189 views
1

由于某种原因,我不知道我的PHP头函数不会重新指引我的脚本到一个新的页面。我知道在函数调用之前没有输出可以发送到屏幕,但是,尽管我没有看到任何输出到屏幕,但我的脚本仍然无法正常工作。我的代码如下。如果代码块执行几次,则该代码执行几次,然后将用户重定向到相应的页面。使用php头函数的问题

这里是代码:

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 = '[email protected]'; 
    $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“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

你总是可以使用HTML标题重定向是我用的时候PHP头的位置没有响应,由于一些很难发现错误。 http://example.com/“/> 您必须将其回显出来,像回复html标记一样回显html元标记,或者您可以整齐地将其放在分隔符外