php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #4124 cookies and headers dont mix
Submitted: 2000-04-12 22:17 UTC Modified: 2000-04-13 02:34 UTC
From: tim dot nelson at mindspring dot com Assigned:
Status: Closed Package: Misbehaving function
PHP Version: 3.0.16 OS: win nt
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: tim dot nelson at mindspring dot com
New email:
PHP Version: OS:

 

 [2000-04-12 22:17 UTC] tim dot nelson at mindspring dot com
When I use both setcookie and header the cookie does not get written. For example...

The following writes a cookie properly

setcookie("name", "value", time()+86400);

The following does not... the cookie just never materializes.

header("Location: nextpage.php3");
setcookie("name", "value", time()+86400);

I am using identical code at mindspring and my local NT server, and mindspring works (v3.0.14 on alpha/Linux) but my machine does not (v3.0.16 intel/NT).



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2000-04-12 23:25 UTC] rasmus at cvs dot php dot net
Setting a cookie and doing a redirect on the same request is not guaranteed to work and is very much both server and browser dependant.
It is not a PHP issue.
 [2000-04-13 02:34 UTC] tim dot nelson at mindspring dot com
problem... there is a "bug" with IIS 

from microsoft support on Microsoft Internet Information Server versions 3.0, 4.0

BUG: Set-Cookie Is Ignored in CGI When Combined With Location

http://support.microsoft.com/support/kb/articles/Q176/1/13.ASP?LNG=ENG&SA=ALLKB&FR=0

work around...

step 1) prefix name of PHP file with "nph-" as in 
  nph-mypage.php3

step 2) the nph- prefix tells IIS to not process the headers, so you must build all the headers yourself. Since we want to redirect and set cookies at the same time, the PHP looks like...

header("HTTP/1.0 302 Redirect");
header("Location: wherever.php3");
setcookie("name","value", $lifetime);

//
Not so simple. Thanks to Patrick for pointing me (although cryptically) in the right direction.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon May 20 18:01:36 2024 UTC