Re: buffering to allow headers in code? [message #170178 is a reply to message #170177] |
Sun, 17 October 2010 02:12 |
Jerry Stuckle
Messages: 2598 Registered: September 2010
Karma:
|
Senior Member |
|
|
On 10/16/2010 4:26 PM, MikeB wrote:
> Thomas 'PointedEars' Lahn wrote:
>> MikeB wrote:
>>
>>>
>>> Do you mind explaining this? If I understand you, if my site is
>>>
>>> http://localhost/recipes/index.php
>>>
>>> I should code:
>>>
>>> header("location: /") ?
>>>
>>> or
>>>
>>> header("location: localhost/recipes/") ?
>>
>> None of the above. You should not need to use the header() function at
>> all:
>>
>> <http://httpd.apache.org/docs/2.2/mod/mod_dir.html#directoryindex>
>
> This is not at all clear to me. You refer me to an Apache page, where I
> cannot programatically code stuff. More specifically, mod.dir is to
> define what happens if i send in a URL without a file and extension.
>
> How does this help me if I'm in the midle of a PHP program and I decide
> I need to reload the page?
>
>
>
>
First of all, "Pointed Ears" is a troll with no idea what he's talking
about. Just check this and other newsgroups.
header() is a perfectly good function to use where necessary. One of
the things it can do is tell the browser to redirect to a new page. But
what Micha is saying is correct - use an absolute URI when redirecting,
i.e. including the domain.
For instance, header('Location:http://www.example.com/recipes'); would
be correct. header('Location:/recipes') would not.
Sure, most browsers today would accept the latter and redirect
accordingly; however, that is not according to the RFC's and is just
something many (not necessarily all) browsers currently do. The former
will work with ALL RFC-compliant browsers.
But as you've noted, this cannot be done after *any* output (even white
space) has been sent to the browser - that is a limitation of the HTTP
protocol, not PHP. The solution is to restructure your code such that
it makes the decision as to whether to redirect (or any other header()
call) is performed before any output to the browser.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
|
|
|