php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #1111 Set-Cookie not working in IE
Submitted: 1999-02-02 01:15 UTC Modified: 1999-02-02 09:46 UTC
From: cary at active-ideas dot com dot au Assigned:
Status: Closed Package: Misbehaving function
PHP Version: 3.0.6 OS: Irix 6.5.2
Private report: No CVE-ID: None
 [1999-02-02 01:15 UTC] cary at active-ideas dot com dot au
We are using PHP as a standalone cgi bin program running various versions of Apache. Even with PHP 3.06 and Apache 1.3.3 this problem still exists.

It appears that Internet Explorer requires the Set-Cookie header tag to be AFTER the Content-Type line in the header returned by PHP.

When using the setcookie function it has performed correctly when using the Netscape browsers. Whereas some websites I noticed were correctly setting a cookie in IE3 and IE4. On doing a comparison of the headers returned (by telnetting to port 80 and requesting the output of the PHP program with a setcookie function) it was apparent that the Set-Cookie Header tag was being output before the Content-type tag. For the web sites that were able to succesfully set a cookie in an Explorer site, they always send the Set-Cookie tag after the Content-Type tag. 

On looking through PHP's source code, it appears that any Content-Type commands are always output last. That is they are queued as the last thing to be output. This is causing the PHP setcookie function to fail when Internet Explorer browsers are being used.

We tried to overcome this by using the Header function to output a Content-Type tag before the setcookie function was called. But this was not output immediately and queued for the end when the entire header is flushed out. If this was possible to output the Content-Type header tag, then it should solve the problem. Alternatively, the order of the header tags needs to be re-arranged so that they are output correctly for IE to understand.

Patches

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [1999-02-02 09:46 UTC] rasmus
You are making it sound as if IE never sets a cookie if the Content-Type header is sent last.  That is simply not true.  Point your browser at www.lerdorf.on.ca/c.php3 for example and then go to www.lerdorf.on.ca/info.php3.  You will see that two cookies were set;  test[0] and test[1].  And if you telnet to the server (use a Host header) you will see that the content-type line is sent last.

The order of the headers is not specified by PHP in the Apache module version.  All PHP does is fill in a table of headers.  Apache decides which order they should be sent in.  And as per the HTTP spec, the order is supposed to be irrelevant.
 [2003-03-27 17:16 UTC] sergio at sergiomoura dot cjb dot net
Ok. I've tested many ways trying to set a cookie to IE with PHP. I know a lot of ways that you can use to FAIL trying to send a cookie to IE. But now, does anybody know how can I set a cookie to IE?

Thanx!
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Aug 14 19:01:27 2024 UTC