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