location header WORKING after content written...why?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • pinbot@gmail.com

    location header WORKING after content written...why?

    As far as I know, http headers should not work after content has been
    written. This is how my production box is working, but for some reason
    on my dev box I was getting away with a location header after content
    (some debug notes) was written.

    Just to be sure, I threw a die() in right before the header('Locatio n:
    '...) call, and sure enough there was the same stuff on screen that
    the live box is choking on.

    So does anyone have any ideas on what I might have set that allowed me
    to get away with this? It's not a capability I enjoy. Environment is
    Apache 2 on Redhat AS3.

    Many thanks

  • Andy Hassall

    #2
    Re: location header WORKING after content written...why?

    On 20 Apr 2005 10:48:16 -0700, pinbot@gmail.co m wrote:
    [color=blue]
    >As far as I know, http headers should not work after content has been
    >written. This is how my production box is working, but for some reason
    >on my dev box I was getting away with a location header after content
    >(some debug notes) was written.
    >
    >Just to be sure, I threw a die() in right before the header('Locatio n:
    >'...) call, and sure enough there was the same stuff on screen that
    >the live box is choking on.
    >
    >So does anyone have any ideas on what I might have set that allowed me
    >to get away with this? It's not a capability I enjoy. Environment is
    >Apache 2 on Redhat AS3.[/color]

    You can get away with it if output buffering is on and you write the header
    before the first flush.

    --
    Andy Hassall / <andy@andyh.co. uk> / <http://www.andyh.co.uk >
    <http://www.andyhsoftwa re.co.uk/space> Space: disk usage analysis tool

    Comment

    • Malcolm Dew-Jones

      #3
      Re: location header WORKING after content written...why?

      pinbot@gmail.co m wrote:
      : As far as I know, http headers should not work after content has been
      : written. This is how my production box is working, but for some reason
      : on my dev box I was getting away with a location header after content
      : (some debug notes) was written.

      perhaps the debug messages are not going to stdout, and perhaps stdout is
      not being sent to the browser.

      --

      This space not for rent.

      Comment

      • pinbot@gmail.com

        #4
        Re: location header WORKING after content written...why?

        No output buffering going on--at least theres no ob_start calls in any
        of the files involved. Could there be some kind of buffering as a
        server configuration? That sounds pretty strange.

        Also, the debug in question boils down to a print_r call, so I haven't
        knowingly done anything to route that output anywhere unusual.

        Thanks for the replies, of course.

        Still baffled.

        Comment

        • Andy Hassall

          #5
          Re: location header WORKING after content written...why?

          On 20 Apr 2005 12:51:06 -0700, pinbot@gmail.co m wrote:
          [color=blue]
          >No output buffering going on--at least theres no ob_start calls in any
          >of the files involved. Could there be some kind of buffering as a
          >server configuration? That sounds pretty strange.[/color]

          There are transparent compression options in php.ini that use the output
          buffering mechanism; these could be turned on.

          --
          Andy Hassall / <andy@andyh.co. uk> / <http://www.andyh.co.uk >
          <http://www.andyhsoftwa re.co.uk/space> Space: disk usage analysis tool

          Comment

          • CJ Llewellyn

            #6
            Re: location header WORKING after content written...why?

            On Wed, 20 Apr 2005 19:55:54 +0100, Andy Hassall wrote:
            [color=blue]
            > On 20 Apr 2005 10:48:16 -0700, pinbot@gmail.co m wrote:
            >[color=green]
            >>As far as I know, http headers should not work after content has been
            >>written. This is how my production box is working, but for some reason
            >>on my dev box I was getting away with a location header after content
            >>(some debug notes) was written.
            >>
            >>Just to be sure, I threw a die() in right before the header('Locatio n:
            >>'...) call, and sure enough there was the same stuff on screen that
            >>the live box is choking on.
            >>
            >>So does anyone have any ideas on what I might have set that allowed me
            >>to get away with this? It's not a capability I enjoy. Environment is
            >>Apache 2 on Redhat AS3.[/color]
            >
            > You can get away with it if output buffering is on and you write the header
            > before the first flush.[/color]

            as per:-



            Comment

            • R. Rajesh Jeba Anbiah

              #7
              Re: location header WORKING after content written...why?

              pinbot@gmail.co m wrote:[color=blue]
              > No output buffering going on--at least theres no ob_start calls in[/color]
              any[color=blue]
              > of the files involved. Could there be some kind of buffering as a
              > server configuration? That sounds pretty strange.[/color]
              <snip>

              Was it really header('Locatio n..') or header('Refresh ...')? The later
              will work after writing the contents.

              --
              <?php echo 'Just another PHP saint'; ?>
              Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/

              Comment

              • Andy Hassall

                #8
                Re: location header WORKING after content written...why?

                On 24 Apr 2005 02:40:37 -0700, "R. Rajesh Jeba Anbiah"
                <ng4rrjanbiah@r ediffmail.com> wrote:
                [color=blue]
                >pinbot@gmail.c om wrote:[color=green]
                >> No output buffering going on--at least theres no ob_start calls in[/color]
                >any[color=green]
                >> of the files involved. Could there be some kind of buffering as a
                >> server configuration? That sounds pretty strange.[/color]
                > <snip>
                >
                > Was it really header('Locatio n..') or header('Refresh ...')? The later
                >will work after writing the contents.[/color]

                No, it won't. Refresh is not an HTTP header, and headers still cannot be sent
                after content.

                Perhaps you're thinking of a <meta> tag within the content.

                --
                Andy Hassall / <andy@andyh.co. uk> / <http://www.andyh.co.uk >
                <http://www.andyhsoftwa re.co.uk/space> Space: disk usage analysis tool

                Comment

                • R. Rajesh Jeba Anbiah

                  #9
                  Re: location header WORKING after content written...why?

                  Andy Hassall wrote:[color=blue]
                  > On 24 Apr 2005 02:40:37 -0700, "R. Rajesh Jeba Anbiah"
                  > <ng4rrjanbiah@r ediffmail.com> wrote:[/color]
                  <snip>[color=blue][color=green]
                  > > Was it really header('Locatio n..') or header('Refresh ...')? The[/color][/color]
                  later[color=blue][color=green]
                  > >will work after writing the contents.[/color]
                  >
                  > No, it won't. Refresh is not an HTTP header, and headers still[/color]
                  cannot be sent[color=blue]
                  > after content.
                  >
                  > Perhaps you're thinking of a <meta> tag within the content.[/color]

                  No. I'm talking about header('Refresh : 5;
                  URL=http://www.example.com/')--not sure if it is a standard header and
                  in HTTP spec. Though the header has to be sent before contents, in the
                  page the redirection will happen only after outputting the
                  contents--same like META refresh. Thought that OP is talking about
                  similar situation.

                  --
                  <?php echo 'Just another PHP saint'; ?>
                  Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/

                  Comment

                  • Andy Hassall

                    #10
                    Re: location header WORKING after content written...why?

                    On 24 Apr 2005 05:15:46 -0700, "R. Rajesh Jeba Anbiah"
                    <ng4rrjanbiah@r ediffmail.com> wrote:
                    [color=blue]
                    >Andy Hassall wrote:[color=green]
                    >> On 24 Apr 2005 02:40:37 -0700, "R. Rajesh Jeba Anbiah"
                    >> <ng4rrjanbiah@r ediffmail.com> wrote:[/color]
                    > <snip>[color=green][color=darkred]
                    >> > Was it really header('Locatio n..') or header('Refresh ...')? The[/color][/color]
                    >later[color=green][color=darkred]
                    >> >will work after writing the contents.[/color]
                    >>
                    >> No, it won't. Refresh is not an HTTP header, and headers still[/color]
                    >cannot be sent[color=green]
                    >> after content.
                    >>
                    >> Perhaps you're thinking of a <meta> tag within the content.[/color]
                    >
                    > No. I'm talking about header('Refresh : 5;
                    >URL=http://www.example.com/')--not sure if it is a standard header and
                    >in HTTP spec.[/color]

                    It is not.



                    --
                    Andy Hassall / <andy@andyh.co. uk> / <http://www.andyh.co.uk >
                    <http://www.andyhsoftwa re.co.uk/space> Space: disk usage analysis tool

                    Comment

                    • R. Rajesh Jeba Anbiah

                      #11
                      Re: location header WORKING after content written...why?

                      Andy Hassall wrote:
                      <snip>[color=blue][color=green]
                      > > No. I'm talking about header('Refresh : 5;
                      > >URL=http://www.example.com/')--not sure if it is a standard header[/color][/color]
                      and[color=blue][color=green]
                      > >in HTTP spec.[/color]
                      >
                      > It is not.
                      >
                      > http://www.w3.org/Protocols/rfc2616/rfc2616.html[/color]

                      Oh, thanks. FWIW, IIRC, I read somewhere that header('Locatio n..')
                      will crash IIS, but not header refresh.

                      --
                      <?php echo 'Just another PHP saint'; ?>
                      Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/

                      Comment

                      • Andy Hassall

                        #12
                        Re: location header WORKING after content written...why?

                        On 24 Apr 2005 05:29:51 -0700, "R. Rajesh Jeba Anbiah"
                        <ng4rrjanbiah@r ediffmail.com> wrote:
                        [color=blue]
                        >Andy Hassall wrote:
                        > <snip>[color=green][color=darkred]
                        >> > No. I'm talking about header('Refresh : 5;
                        >> >URL=http://www.example.com/')--not sure if it is a standard header[/color][/color]
                        >and[color=green][color=darkred]
                        >> >in HTTP spec.[/color]
                        >>
                        >> It is not.
                        >>
                        >> http://www.w3.org/Protocols/rfc2616/rfc2616.html[/color]
                        >
                        > Oh, thanks. FWIW, IIRC, I read somewhere that header('Locatio n..')
                        >will crash IIS, but not header refresh.[/color]

                        The only references I can find to this is are certain circumstances where
                        sending a relative URI through Location on old versions of ISS reportedly
                        results in a crash. This is forbidden by the standards anyway, you must send an
                        absolute URI in the first place.

                        Presumably it doesn't crash using Refresh because this is a made-up header and
                        so there's no additional code it runs to correct relative URIs.

                        --
                        Andy Hassall / <andy@andyh.co. uk> / <http://www.andyh.co.uk >
                        <http://www.andyhsoftwa re.co.uk/space> Space: disk usage analysis tool

                        Comment

                        Working...