php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #42969 header("Location:") changing HTTP status
Submitted: 2007-10-15 09:24 UTC Modified: 2007-10-19 11:16 UTC
From: gustav at cst dot co dot za Assigned:
Status: Not a bug Package: HTTP related
PHP Version: 5.2.4 OS: Windows Server 2003
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: gustav at cst dot co dot za
New email:
PHP Version: OS:

 

 [2007-10-15 09:24 UTC] gustav at cst dot co dot za
Description:
------------
This bug is identical to bug #25044.

When a form is posted to a PHP script, and that script wants to forward the browser to another page, the correct HTTP response header code is 303.

But, when setting the "Location" HTTP header using the header() function, PHP automatically changes the HTTP response status to "302 Found". 

This is important because some mobile browsers (Specifically Motorola V360 and Nokia 6310i) will *not* immediately redirect a script that received a post when the code is 302, but *will* when the code is 303.

I have recreated this problem on both IIS 6 and Apache.

NOTE: The suggested workarounds in bug #25044 do *not* work.

Reproduce code:
---------------
<?php
    header('Status: 303 See Other');
    header('Location: http://www.example.com/');
    die();
?>

---OR---

<?php
    header('HTTP/1.1 303 See Other');
    header('Location: http://www.example.com/');
    die();
?>


Expected result:
----------------
HTTP/1.1 303 See Other
Location: http://www.example.com/

Actual result:
--------------
HTTP/1.0 302 Moved
Location: http://www.example.com/

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-10-18 02:04 UTC] carsten_sttgt at gmx dot de
According to the PHP manual for header(), you want use:
| header('Location: http://www.example.com/', true, 303);

Regards,
Carsten
 [2007-10-18 08:12 UTC] gustav at cst dot co dot za
Hi,

I tested that variation of the code before I made my bug report. Alas, it still doesn't work.

If it works on your setup, I'd be very interested in finding out how/why. Have you tested it?

Regards,
Gustav
 [2007-10-18 16:17 UTC] carsten_sttgt at gmx dot de
> If it works on your setup, I'd be very interested in finding out
> how/why. Have you tested it?

Sure:
| C:\php>php -v
| PHP 5.2.4 (cli) (built: Aug 30 2007 07:06:31)
| 
| C:\php>type C:\www\htdocs\test.php
| <?php header('Location: http://www.example.com/', true, 303); ?>
| 
| C:\php>GET -S -m head http://localhost/test.php
| HEAD http://localhost/test.php --> 303 See Other
| HEAD http://www.example.com/ --> 200 OK
| Connection: close
| 
| 
| C:\php>

Regards,
Carsten
 [2007-10-19 11:16 UTC] gustav at cst dot co dot za
Hi,

I use Wireshark to keep track of the traffic. (What is that "GET" utility you are using? Can't use network monitor to test localhost...)

Here are the results of the tests using the code you gave me.

Clean WAMP installation - Actually works, returns "303 See Other".

IIS with FastCGI (http://www.caraveo.com/fastcgi/) interface - Still broken, and the setup that we use in production.

IIS with ISAPI - *Sort of* works. Manage to get "303 Unspecified" but still no "303 See Other".

Played a bit around with the code though, and the following...

    header('HTTP/1.1 303 See Other');
    header('Location: http://www.example.com/');   

... actually works on IIS with ISAPI. Returns "303 See Other" and everything.

In conclusion - This bug turns out to be bogus. (It'd be nice if header function wore improved though.) We're looking for a FastCGI replacement for IIS, but it looks like MS is finally developing just that: http://www.iis.net/default.aspx?tabid=1000051

Thanks for all the help!

Regards,
Gustav
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 12:01:31 2024 UTC