[PHP-DEV] Bug #1347: setcookie executes after previous cookie value is read From: jwillis <email protected>
Date: 04/24/99

From: jwillis <email protected>
Operating system: Windows NT 4.0
PHP version: 3.0.7
PHP Bug Type: Misbehaving function
Bug description: setcookie executes after previous cookie value is read

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 think 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

--
PHP Development Mailing List   http://www.php.net/
To unsubscribe send an empty message to php-dev-unsubscribe <email protected>
For help: php-dev-help <email protected>