[PHP-DEV] Bug #1347 Updated: setcookie executes after previous cookie value is read From: Bug Database (php-dev <email protected>)
Date: 04/24/99

ID: 1347
User Update by: jwillis <email protected>
Status: Open
Bug Type: Misbehaving function
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 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

Full Bug description available at: http://bugs.php.net?id=1347

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