Click here to Skip to main content
15,916,945 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am having some trouble using the header function in php. My code is supposed to check several Boolean values and execute the appropriate block of code. When I execute the script I get this error message,"Warning: Cannot modify header information - headers already sent by (output started at /home2/truck35/public_html/ShowLove/Captcha_Post.php:34) in /home2/truck35/public_html/ShowLove/Captcha_Post.php on line 73". I read that no characters are supposed to be outputted before the function call but, I am a little confused what is actually meant by this. The script works on my development WAMP server. Any help would be appreciated. Here is the script that I am working on.

<?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');
}

if (!$email_result)
{
	$_SESSION['Form_Email_Switch'] = false;
	header('location:Contact_Form.php');
}

if($response != $image_request)
{
	 
	//unset($_SESSION['Form_Switch']);
	unset($_SESSION['Email_Switch']);
	header('location:Contact_Form.php');
}

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');
}
?>


What I have tried:

I tried using the ob_start() and ob_end_clean() functiona for output buffering but, they do not work.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900