Cannot modify header information - headers already sent by

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • J Huntley Palmer

    Cannot modify header information - headers already sent by

    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

    #2
    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

    Comment

    • J Huntley Palmer

      #3
      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]

      Comment

      • monomaniac21

        #4
        Re: Cannot modify header information - headers already sent by

        BTW i just posted that exact question earlier today!

        Comment

        • Rik

          #5
          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:

          "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


          Comment

          • Martin Jay

            #6
            Re: Cannot modify header information - headers already sent by

            In message <1147724764.604 567.50720@y43g2 000cwc.googlegr oups.com>,
            monomaniac21 <mcyi2mr3@googl email.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

            Comment

            Working...