Cannot modify header information - PLEASE HELP!!!!!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
5leander5
Forum Commoner
Posts: 31
Joined: Thu Mar 09, 2006 3:45 am

Cannot modify header information - PLEASE HELP!!!!!

Post by 5leander5 »

feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]


I am getting the 

Warning: Cannot modify header information - headers already sent by (output started at /home/bertspar/public_html/ExpressionOfInterest5.php:7) in /home/bertspar/public_html/ExpressionOfInterest5.php on line 53

error and cannot see where I am going wrong. If someone could take a look at the very simple script below, and see if they can see whats wrong, I would REALLY appreciate it. Thanks.

Code: Select all

<?php 
session_start();?>
<html>
<head>
<title>Expression Of Interest</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
.style1 {color: #FF0000}
.style3 {color: #FF0000; font-size: 10px; }
-->
</style>
<link href="bert2.css" rel="stylesheet" type="text/css">
</head>

<?php
if(isset($_POST['Submit'])){ 
foreach($_POST as $key => $val) 
{ 
$_SESSION[$key] = $val; 
} 

$status = "full";
if($_SESSION['Title'] == NULL) $status = "empty"; 
if($_SESSION['Name'] == NULL) $status = "empty"; 
if($_SESSION['Initial'] == NULL) $status = "empty"; 
if($_SESSION['Surname'] == NULL) $status = "empty"; 
if($_SESSION['Position'] == NULL) $status = "empty"; 
if($_SESSION['Company'] == NULL) $status = "empty"; 
if($_SESSION['Address1'] == NULL) $status = "empty"; 
if($_SESSION['Country'] == NULL) $status = "empty"; 
if($_SESSION['ContactNumber'] == NULL) $status = "empty"; 
if($_SESSION['Email'] == NULL) $status = "empty"; 

if($status == "full") {
$body = $_SESSION['Title']."\n"; 
$body .= $_SESSION['Name']."\n"; 
$body .= $_SESSION['Initial']."\n"; 
$body .= $_SESSION['Surname']."\n"; 
$body .= $_SESSION['Position']."\n"; 
$body .= $_SESSION['Company']."\n"; 
$body .= $_SESSION['Address1']."\n"; 
$body .= $_SESSION['Address2']."\n"; 
$body .= $_SESSION['Address3']."\n"; 
$body .= $_SESSION['Country']."\n"; 
$body .= $_SESSION['ContactNumber']."\n"; 
$body .= $_SESSION['CellNumber']."\n"; 
$body .= $_SESSION['Email']."\n"; 
$email = $_SESSION['Email'];
mail("albert_oflaherty@hotmail.com", "Expression Of Interest in Forum on Public Safety 2006", $body, "From: $email" ); 
empty($_POST);
//session_write_close();
header("Location: Confirmation.htm");
}
}
?>

<body>
<form name="ExpressionInterest" method="post" action="ExpressionOfInterest4.php"> 
       <blockquote>
         <p align="center"><img src="Formtitle.jpg" width="852" height="286" align="middle"></p>
		 <?php
if(isset($_SESSION['Submit'])){ 
echo "Please complete the mandatory fileds. Thank you.";
}
?>
         <p align="center"><strong>REGISTER YOUR INTEREST </strong></p>
         <p align="center">If you would like to register your interest in attending this event, please complete and </p>
         <p align="center">return this form via fax to Norrie Keane at the following number: +353 (0)93 43887. &nbsp; </p>
         <p align="center"><strong><span class="style1">*</span>Title </strong>:
           <select name="Title" size="1" tabindex="1" dir="ltr">
        <option> </option>
        <option>Dr.</option>
        <option>Mr.</option>
        <option>Mrs.</option>
        <option>Miss.</option>
           </select>    
           &nbsp;<strong><span class="style1">*</span></strong><strong>Name </strong>:<strong>
		   
           <input name="Name" type="text" value="<?php if(isset($_SESSION['Name'])){
		echo($_SESSION['Name']);}?>" tabindex="2" size="28">
           </strong>&nbsp;<strong><span class="style1">*</span>Middle Initial </strong>: 
           <input name="Initial" type="text" value="<?php if(isset($_SESSION['Initial'])){
		echo($_SESSION['Initial']);}?>" tabindex="3" size="3" maxlength="3">
         </p>
       </blockquote>      
       <p align="center"><strong><span class="style1">*</span>Surname </strong>:
         &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input name="Surname" type="text" value="<?php if(isset($_SESSION['Surname'])){
		echo($_SESSION['Surname']);}?>" tabindex="4" size="67">
  </p>
       <blockquote>
         <p align="center"><strong><span class="style1">*</span>Position </strong>:&nbsp; 
           &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input name="Position" type="text" value="<?php if(isset($_SESSION['Position'])){
		echo($_SESSION['Position']);}?>" tabindex="5" size="67">
         </p>
         <p align="center"><strong> <span class="style1">*</span>Company </strong>: 
           &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input name="Company" type="text" value="<?php if(isset($_SESSION['Company'])){
		echo($_SESSION['Company']);}?>" tabindex="6" size="67">
         </p>
         <p align="center"><strong><span class="style1">*</span>Address </strong>: <?php echo(str_repeat('&nbsp;',7));?> <input name="Address1" type="text" value="<?php if(isset($_SESSION['Address1'])){
		echo($_SESSION['Address1']);}?>"tabindex="7" size="67">
         </p>
         <p align="center"> <?php echo(str_repeat('&nbsp;',23));?>
           <input name="Address2" type="text" value="<?php if(isset($_SESSION['Address2'])){
		echo($_SESSION['Address2']);}?>" tabindex="8" size="67">
         </p>
  </blockquote>
       <blockquote>
         <div align="center"></div>
         <div align="center"> <?php echo(str_repeat('&nbsp;',23));?>
           <input name="Address3" type="text" value="<?php if(isset($_SESSION['Address3'])){
		echo($_SESSION['Address3']);}?>" tabindex="9" dir="ltr" size="67">
         </div>
       </blockquote>
       <p align="center">    <strong><span class="style1">*</span>Country </strong>:       
    <?php echo(str_repeat('&nbsp;',6));?> <input name="Country" type="text" value="<?php if(isset($_SESSION['Country'])){
		echo($_SESSION['Country']);}?>" tabindex="10" size="67">
  </p>
  <p align="center"><strong> <span class="style1">*</span>Contact No </strong>:
    &nbsp;&nbsp;<input name="ContactNumber" type="text" value="<?php if(isset($_SESSION['ContactNumber'])){
		echo($_SESSION['ContactNumber']);}?>" tabindex="11" size="67">
  </p>
  <p align="center">(Please include country code) <?php echo(str_repeat('&nbsp;',84));?>
  </p>
  <p align="center"><strong>Cell Phone </strong>: 
    &nbsp;&nbsp;&nbsp;&nbsp;<input name="CellNumber" type="text" value="<?php if(isset($_SESSION['CellNumber'])){
		echo($_SESSION['CellNumber']);}?>" tabindex="12" size="67">
  </p>
  <p align="center">(Please include country code) <?php echo(str_repeat('&nbsp;',84));?>
  </p>
  <p align="center"><strong><span class="style1">*</span>Email </strong>:
    <?php echo(str_repeat('&nbsp;',11));?>
    <input name="Email" type="text" value="<?php if(isset($_SESSION['Email'])){
		echo($_SESSION['Email']);}?>" tabindex="13" size="67">
  </p>
  <p align="center"><strong><span class="style1">*</span></strong> <span class="style3">Mandatory Fields</span></p>
  <p align="center">By completing this form, you will receive regular, updated Forum information, via email, </p>
  <p align="center">as it becomes available, and an official invitation and information pack will be forwarded </p>
  <p align="center">&nbsp;to you via post in due course. </p>
  <p align="center">
    <input name="Submit" type="submit" tabindex="14" value="Submit">
    &nbsp;&nbsp;&nbsp;&nbsp;<input name="Reset" type="reset" tabindex="15" value="Reset">
  &nbsp;&nbsp;&nbsp; </p>
</form>
<p align="center">___________________________________________________________________________________ </p>
<p align="center">Moyne Park, Tuam, Co. Galway, Ireland &nbsp; </p>
<p align="center">Telephone: +353 (0)93 43900 Facsimile: +353 (0)93 43887 &nbsp; Email: nkeane@rivada.com </p>

</body>
</html>

feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

User avatar
NightFox
Forum Newbie
Posts: 13
Joined: Sat Mar 11, 2006 3:20 am

Post by NightFox »

Here's how I do it so I don't really have to worry about whether the headers have already been sent or not.
I usually start with sending the header, and if I get an error, I just use the script:

Code: Select all

function redirect($location, $type="header") {
	if ($type == "header") {
		header("Location: ".$location);
	} else {
		echo "<script type='text/javascript'>document.location.href='".$location."'</script>\n";
	}
}

Code: Select all

if (!$username && !$password) {
      redirect("login.php?invalid=1"); // uses header to redirect
} else {
      redirect("members.php","script"); // uses script to redirect (anything but the word "header" will activate the script vs the header)
}
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

or you could simply design your application to only ever output anything until your entire site is processed ;)
Post Reply