php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #24177 header() call doesn't replace 404 status code
Submitted: 2003-06-13 13:42 UTC Modified: 2003-08-02 13:30 UTC
From: ohrn@php.net Assigned: iliaa (profile)
Status: Closed Package: Apache2 related
PHP Version: 4.3.3RC2-dev OS: Linux
Private report: No CVE-ID: None
 [2003-06-13 13:42 UTC] ohrn@php.net
Description:
------------
Using Apache 2.0.46 and PHP 4.3.2 compiled with --with-apxs2

When a PHP page is used as an ErrorDocument page, calling any variation of header() to replace the status code doesn't work. The client always receive 404.

For example, try downloading from se.php.net:
http://se.php.net/get/php-4.3.2.tar.gz/from/this/mirror

You'll se that a Location header has been added (by the call to header() in /include/do-download.inc) but the status returned is still 404, not 302 as expected.


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-06-13 15:19 UTC] sniper@php.net
# lynx -dump -head http://se.php.net/imap
HTTP/1.1 200 OK
Date: Fri, 13 Jun 2003 19:17:17 GMT
Server: Apache/2.0.46 (Unix) mod_ssl/2.0.46 OpenSSL/0.9.6b PHP/4.3.2
X-Powered-By: PHP/4.3.2
Content-language: en
Set-Cookie: COUNTRY=FIN%2C213.243.181.8; expires=Fri, 20-Jun-2003 19:17:17 GMT;
 path=/; domain=.php.net
Status: 200 OK
Last-Modified: Fri, 13 Jun 2003 19:09:38 GMT
Vary: Cookie
Connection: close
Content-Type: text/html;charset=ISO-8859-1

That works just fine?

 [2003-06-15 10:20 UTC] ohrn@php.net
Yes. Odd at first.

After some experimentation I figured it out.

do-download.inc calls flush() on line 31. This causes the 'original' status to be sent instead of the one specified by the call to header().

If 4096 bytes or more are written before the flush the correct status is sent.

I guess the codepath that handles an expicit flush manages to loose the new status code somewhere.

I replaced echo " " with echo str_repeat(' ', 4096) and now our mirror works fine and dandy again.
 [2003-07-10 23:48 UTC] sniper@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php4-STABLE-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php4-win32-STABLE-latest.zip


Can you do a favor and test the latest CVS? 
I have no time to setup a mirror just to test this.. :)

 [2003-07-17 10:10 UTC] ohrn@php.net
I've just tried out php4-STABLE-200307171330 and the problem is still present.

I'll write a small testcase during the weekend so that you can easily verify the bug.

Regards,
Fredrik
 [2003-08-01 05:05 UTC] ohrn@php.net
Summer is a killer on productivity. :)

Finally, here's the testcase I promised. It ended up pretty short...

Put the following lines in handler.php

<?
header ("location: http://www.php.net/");
flush ();
?>

Add ErrorDocument 404 /handler.php to your Apache config.

# lynx --head --dump http://mysite.com/nonexistant
HTTP/1.1 404 Not Found
Date: Fri, 01 Aug 2003 09:54:16 GMT
Server: Apache/2.0.46 (Unix) mod_ssl/2.0.46 OpenSSL/0.9.6b PHP/4.3.3RC3-dev
X-Powered-By: PHP/4.3.3RC3-dev
location: http://www.php.net/

Connection: close
Content-Type: text/html; charset=ISO-8859-1


Incorrect status 404, should be 302.
Remove flush(); from handler.php and try again:

# lynx --head --dump http://mysite.com/nonexistant
HTTP/1.1 302 Found
Date: Fri, 01 Aug 2003 09:56:17 GMT
Server: Apache/2.0.46 (Unix) mod_ssl/2.0.46 OpenSSL/0.9.6b PHP/4.3.3RC3-dev
X-Powered-By: PHP/4.3.3RC3-dev
location: http://www.php.net/
Connection: close
Content-Type: text/html; charset=ISO-8859-1


Now it works as expected. Apparently, somewhere inside flush() the status is reset to 404.

Regards,
Fredrik
 [2003-08-02 13:30 UTC] iliaa@php.net
This bug has been fixed in CVS.

In case this was a PHP problem, snapshots of the sources are packaged
every three hours; this change will be in the next snapshot. You can
grab the snapshot at http://snaps.php.net/.
 
In case this was a documentation problem, the fix will show up soon at
http://www.php.net/manual/.

In case this was a PHP.net website problem, the change will show
up on the PHP.net site and on the mirror sites in short time.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Dec 03 17:01:29 2024 UTC