Connecting Tech Pros Worldwide Help | Site Map

location header WORKING after content written...why?

pinbot@gmail.com
Guest
 
Posts: n/a
#1: Jul 17 '05
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('Location:
'...) 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
Guest
 
Posts: n/a
#2: Jul 17 '05

re: location header WORKING after content written...why?


On 20 Apr 2005 10:48:16 -0700, pinbot@gmail.com 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('Location:
>'...) 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.andyhsoftware.co.uk/space> Space: disk usage analysis tool
Malcolm Dew-Jones
Guest
 
Posts: n/a
#3: Jul 17 '05

re: location header WORKING after content written...why?


pinbot@gmail.com 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.
pinbot@gmail.com
Guest
 
Posts: n/a
#4: Jul 17 '05

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.

Andy Hassall
Guest
 
Posts: n/a
#5: Jul 17 '05

re: location header WORKING after content written...why?


On 20 Apr 2005 12:51:06 -0700, pinbot@gmail.com 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.andyhsoftware.co.uk/space> Space: disk usage analysis tool
CJ Llewellyn
Guest
 
Posts: n/a
#6: Jul 17 '05

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.com 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('Location:
>>'...) 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:-

http://www.php.net/manual/en/ref.out...tput-buffering

R. Rajesh Jeba Anbiah
Guest
 
Posts: n/a
#7: Jul 17 '05

re: location header WORKING after content written...why?


pinbot@gmail.com 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('Location..') 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/

Andy Hassall
Guest
 
Posts: n/a
#8: Jul 17 '05

re: location header WORKING after content written...why?


On 24 Apr 2005 02:40:37 -0700, "R. Rajesh Jeba Anbiah"
<ng4rrjanbiah@rediffmail.com> wrote:
[color=blue]
>pinbot@gmail.com 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('Location..') 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.andyhsoftware.co.uk/space> Space: disk usage analysis tool
R. Rajesh Jeba Anbiah
Guest
 
Posts: n/a
#9: Jul 17 '05

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@rediffmail.com> wrote:[/color]
<snip>[color=blue][color=green]
> > Was it really header('Location..') 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/

Andy Hassall
Guest
 
Posts: n/a
#10: Jul 17 '05

re: location header WORKING after content written...why?


On 24 Apr 2005 05:15:46 -0700, "R. Rajesh Jeba Anbiah"
<ng4rrjanbiah@rediffmail.com> wrote:
[color=blue]
>Andy Hassall wrote:[color=green]
>> On 24 Apr 2005 02:40:37 -0700, "R. Rajesh Jeba Anbiah"
>> <ng4rrjanbiah@rediffmail.com> wrote:[/color]
> <snip>[color=green][color=darkred]
>> > Was it really header('Location..') 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.

http://www.w3.org/Protocols/rfc2616/rfc2616.html

--
Andy Hassall / <andy@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
R. Rajesh Jeba Anbiah
Guest
 
Posts: n/a
#11: Jul 17 '05

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('Location..')
will crash IIS, but not header refresh.

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

Andy Hassall
Guest
 
Posts: n/a
#12: Jul 17 '05

re: location header WORKING after content written...why?


On 24 Apr 2005 05:29:51 -0700, "R. Rajesh Jeba Anbiah"
<ng4rrjanbiah@rediffmail.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('Location..')
>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.andyhsoftware.co.uk/space> Space: disk usage analysis tool
Closed Thread