Jump to content


Photo

Cannot Modify Header Information


  • Please log in to reply
4 replies to this topic

#1 Fooleeze

Fooleeze
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 20 June 2006 - 01:03 PM

I've encountered an error that as I understand is relatively common. Here it is:

Warning: Cannot modify header information - headers already sent by (output started at [a href=\"http://www.*mywebsite*.com/v2/header2.php:11)\" target=\"_blank\"]http://www.*mywebsite*.com/v2/header2.php:11)[/a] in /*mywebsite*.com/v2/infoenter.php on line 108

I understand this is commonly referred to the 'whitespace' error, whereas I may have unnecessary whitespace in the 'header2.php' code at line 11. Well, I've gone over this again and again, in different editors, and I cannot get past this. I can't find any extra whitespace.

The 'header2.php' is just a header file that is included at the top of the 'infoenter.php' file.

Here's a short version of what my code is like (infoenter.php). . . file names have been changed to protect the innocent:

<?php
include "http://www.*mywebsit...2/header2.php";
--a bunch of code--
header("Location:infoverify.php?newcust=$newcust");
exit;
--a bunch more code--
?>

That 'header2.php' file is also included in the target location (infoverify.php) in the same manner.

Here is what the header2.php file looks like:

<?php
include_once "functionsfile.php";
formatthebody();
print "<html>
<head>
<title>*MyWebsite.com* - Your Online Source for Sweet Stuff</title>
</head>
<table align=left valign=top width=100%>
<tr>
<td align=left>
<font color=green size=32><b><i>My Website</b></i></font>
</td>
</tr>
<tr>
<td>";
?>

So. . . anybody have any advice to help me fix my problem?

#2 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 20 June 2006 - 01:35 PM

<?php
include "http://www.*mywebsite*.com/v2/header2.php";
--a bunch of code--
If that produces ANY output to the browser then you'll get header errors.
Legend has it that reading the manual never killed anyone.
My site

#3 Fooleeze

Fooleeze
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 20 June 2006 - 02:07 PM

Yes, it does produce output. How do I get around that? I've used this in other places to add a 'header' to my pages. However on this page (where I'm using the header:location. . . ) is where it has issues.



[!--quoteo(post=386006:date=Jun 20 2006, 09:35 AM:name=AndyB)--][div class=\'quotetop\']QUOTE(AndyB @ Jun 20 2006, 09:35 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
<?php
include "http://www.*mywebsite*.com/v2/header2.php";
--a bunch of code--
If that produces ANY output to the browser then you'll get header errors.
[/quote]


#4 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 20 June 2006 - 02:50 PM

header Location redirects the browser elsewhere (to another page/script) so you can check whatever condition would cause the redirect before you output anything to the browser.

For example:
<?php
$something = $_GET['some_value']; // retrieve passed value from another page
if ($something == 6) {
    header("Location: page6.php"); // redirect to page 6
    die();
} else {
    include("page_header.php");
}
... more code ...

Legend has it that reading the manual never killed anyone.
My site

#5 Fooleeze

Fooleeze
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 20 June 2006 - 03:10 PM

Ok, your info pointed me in the right direction. I was putting that 'header2' file at the top (producing output) which was not necessary, so I moved it down into the 'html' section of the code. In addition I had a 'formatting' function that was also producing output, so I moved that down, too. Problem solved.

Thanks a lot for your help.

Todd



[!--quoteo(post=386032:date=Jun 20 2006, 10:50 AM:name=AndyB)--][div class=\'quotetop\']QUOTE(AndyB @ Jun 20 2006, 10:50 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
header Location redirects the browser elsewhere (to another page/script) so you can check whatever condition would cause the redirect before you output anything to the browser.

For example:
<?php
$something = $_GET['some_value']; // retrieve passed value from another page
if ($something == 6) {
    header("Location: page6.php"); // redirect to page 6
    die();
} else {
    include("page_header.php");
}
... more code ...
[/quote]





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users