Re: causing HTTP error status

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 5/6/06, Richard Lynch <ceo@xxxxxxxxx> wrote:
On Fri, May 5, 2006 5:01 am, Nic wrote:
> Hi Rabin
> "Rabin Vincent" <rabin@xxxxxx> writes:
>
>> On 5/5/06, Nic <nferrier@xxxxxxxxxxxxxxxxxxxx> wrote:
>>> But /mydir/some.php doing:
>>>
>>>    header("HTTP/1.1 404 Rubbish!!!")
>>>
>>> _never_ causes the error document to be picked up.
>>
>> That's right. Apache's not going to take action based
>
> mod_perl and mod_python can both do this. As can CGIs. So I'll be
> really surprised if this isn't possible with PHP.
>
>>> It's strange because the docs say this can be done; I can't find an
>>> example that is purported to work outside of the docs though.
>>
>> Where do the docs say this? I can't find it in
>> http://php.net/header.
>
> The url is:
>
>   http://www.php.net/manual/en/function.header.php
>
> The relevant bit is where it says:
>
>    There are two special-case header calls. The first is a header that
>    starts with the string "HTTP/" (case is not significant), which
>    will be used to figure out the HTTP status code to send. For
>    example, if you have configured Apache to use a PHP script to
>    handle requests for missing files (using the ErrorDocument
>    directive), you may want to make sure that your script generates
>    the proper status code.
>
>     <?php
>      header("HTTP/1.0 404 Not Found");
>     ?>

I gotta go with Nic on this...

Either I'm being really obtuse, or it just plain don't work right.

Consider this minimalist example:

http://l-i-e.com/404/test.php
http://l-i-e.com/404/index.htm

The 404 header is being completely ignored, afaict

I tried adding "exit;" right after the header, and my browser just
goes way long time and then times out.

I tried HTTP/1.1 and that made no difference.

I'd suggest checking http://bugs.php.net and filing a bug report if
it's not a known issue...

Unless somebody can point out something wrong in our logic.

The doc paragraph refers to a PHP error handler script. In
the case of a normal script like your test case:

I've just been reading to see why this header throwing does
not cause Apache to kick in its ErrorDocument. Apache allows
handlers to handle different stages of the request, and it
takes action based on what the handler returns after looking
at the request.

In the case of mod_python, mod_python allows you to write
the handler, which would normally be written in C, in Python. Thus,
you can return the 404 code from the handler callback, and
Apache will show ErrorDocument.

In PHP, mod_php itself is the handler. It doesn't allow your script
access to the Apache API in the way that mod_python does. Looking
at the sapi code in PHP, it seems to returns OK to Apache
regradless of what goes on in the called script (i.e, it's not parsing
the headers emitted, if any). Thus, throwing a 404 header in
your script will not invoke Apache's ErrorDocument, since Apache
doesn't know anything is wrong.

I just got that from these two docs, so there may be some
Apache details I'm missing/overlooking:

http://www.modpython.org/python10/
http://httpd.apache.org/docs/1.3/misc/API.html

Rabin

--
http://rab.in

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux