php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #1347 setcookie executes after previous cookie value is read
Submitted: 1999-04-24 03:02 UTC Modified: 1999-05-11 08:12 UTC
From: jwillis at pmz dot com Assigned:
Status: Closed Package: Misbehaving function
PHP Version: 3.0.7 OS: Windows NT 4.0
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: jwillis at pmz dot com
New email:
PHP Version: OS:

 

 [1999-04-24 03:02 UTC] jwillis at pmz dot com
Php seems to be reading the previous cookie value before setting the cookie. So reading the cookie being currently set is quite impossible since it is the last thing done before the header is sent. Here is the snippet code. with two consecutive runs of the script. cookie and sessionid should be the same value.

<?php 
$cookie = microtime();
SetCookie("BIN",$cookie,0,"/");
$sessionid = $BIN;
echo "cookie = ".$cookie."<BR>";
echo "sessionid = ".$sessionid;
exit;
?>

cookie = 230.42169300 924936609
sessionid = 65.21762600 924936436

cookie = 245.03266400 924936625
sessionid = 230.42169300 924936609

As you can see the cookie being read by the $sessionid = $BIN; call is the current cookie before the new cookie gets set even though it is after the setcookie statement. The docs specifically mention that the contents of a cookie can be displayed after being set but this is not the case in the above code.

Just as a comparision when I do the exact same thing with .asp the following occurs

<% 
cookie = CDbl(Now())
Response.Cookies("BIN").path = "/"
Response.Cookies("BIN") = cookie
sessionid = Request.Cookies("BIN")
%>
cookie = <%= cookie %><BR>
sessionid = <%= sessionid %>

cookie = 36274.0025694444
sessionid = 36274.0025694444

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [1999-05-11 08:12 UTC] sas at cvs dot php dot net
Actually, the code is working as expected. There is a little misconception on your side. PHP does not know which cookies you've set within a page. It only makes available cookies which were sent with the HTTP request for the page. ASP differs in this aspect that it knows (remembers) which cookies were set by you in the current script and makes this information available to you.

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Jun 01 09:01:31 2024 UTC