Jump to content

Cannot Modify Header Information


Fooleeze

Recommended Posts

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.*mywebsite*.com/v2/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?
Link to comment
Share on other sites

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) [snapback]386006[/snapback][/div][div class=\'quotemain\'][!--quotec--]
[code]<?php
include "http://www.*mywebsite*.com/v2/header2.php";
--a bunch of code--[/code]
If that produces [b]ANY[/b] output to the browser then you'll get header errors.
[/quote]
Link to comment
Share on other sites

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:
[code]<?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 ...
[/code]
Link to comment
Share on other sites

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) [snapback]386032[/snapback][/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:
[code]<?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 ...
[/code]
[/quote]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.