Connecting Tech Pros Worldwide Help | Site Map

Cannot modify header information - headers already sent by

J Huntley Palmer
Guest
 
Posts: n/a
#1: May 15 '06
I am getting this error:
Cannot modify header information - headers already sent by

when I issue a
header ("Location: http://www.foobar.com");

How can I redirect the user to such a site without encountering this error.

If I run the same code on two sites I will get the error on one site but
not the other.

An I can t figure out what setting in the php.ini that is different.

How can one send a refresh in 0 seconds to the broweser?

Thanks
Gordon Burditt
Guest
 
Posts: n/a
#2: May 15 '06

re: Cannot modify header information - headers already sent by


>Cannot modify header information - headers already sent by[color=blue]
>
>when I issue a
>header ("Location: http://www.foobar.com");[/color]

Move everything that outputs text to *AFTER* the header() call
(or just delete it, as the text won't be seen anyway).

This includes:

- A blank line outside <?php ... ?>
- A blank line in an include file outside <?php ?>, especially
at the start or end of the file.
- A space or tab outside <?php ... ?>
- Invisible unicode characters inserted by an editor before <?php
- Warning or error messages output by anything you call before
header().
- <!DOCTYPE declarations
- html
[color=blue]
>How can I redirect the user to such a site without encountering this error.[/color]

If it tells you where the output started, look there and delete the
offending text. It is likely white space of some sort.

Gordon L. Burditt
J Huntley Palmer
Guest
 
Posts: n/a
#3: May 15 '06

re: Cannot modify header information - headers already sent by


Gordon! Thank you! It was white space after the ?>.
It solved the problem.


Gordon Burditt wrote:[color=blue][color=green]
>> Cannot modify header information - headers already sent by
>>
>> when I issue a
>> header ("Location: http://www.foobar.com");[/color]
>
> Move everything that outputs text to *AFTER* the header() call
> (or just delete it, as the text won't be seen anyway).
>
> This includes:
>
> - A blank line outside <?php ... ?>
> - A blank line in an include file outside <?php ?>, especially
> at the start or end of the file.
> - A space or tab outside <?php ... ?>
> - Invisible unicode characters inserted by an editor before <?php
> - Warning or error messages output by anything you call before
> header().
> - <!DOCTYPE declarations
> - html
>[color=green]
>> How can I redirect the user to such a site without encountering this error.[/color]
>
> If it tells you where the output started, look there and delete the
> offending text. It is likely white space of some sort.
>
> Gordon L. Burditt[/color]
monomaniac21
Guest
 
Posts: n/a
#4: May 15 '06

re: Cannot modify header information - headers already sent by


BTW i just posted that exact question earlier today!

Rik
Guest
 
Posts: n/a
#5: May 15 '06

re: Cannot modify header information - headers already sent by


monomaniac21 wrote:[color=blue]
> BTW i just posted that exact question earlier today![/color]

Hehe, it's a famous question... Not a day goes by without someone asking it
somewhere.

You'd think people would read the manual:
http://nl2.php.net/manual/en/function.header.php
"Remember that header() must be called before any actual output is sent,
either by normal HTML tags, blank lines in a file, or from PHP. It is a very
common error to read code with include(), or require(), functions, or
another file access function, and have spaces or empty lines that are output
before header() is called. The same problem exists when using a single
PHP/HTML file"

But hey, as long as the answer is short and simple, I and others are still
willing to give it :-).

Grtz,
--
Rik Wasmus


Martin Jay
Guest
 
Posts: n/a
#6: May 15 '06

re: Cannot modify header information - headers already sent by


In message <1147724764.604567.50720@y43g2000cwc.googlegroups. com>,
monomaniac21 <mcyi2mr3@googlemail.com> writes[color=blue]
>BTW i just posted that exact question earlier today![/color]

It's a common problem.

Your earlier post didn't arrive here, though. :(
--
Martin Jay
Closed Thread