note 91140 added to function.setcookie

From: Date: Wed, 27 May 2009 08:49:03 +0000
Subject: note 91140 added to function.setcookie
Groups: php.notes 
Request: Send a blank email to php-notes+get-156051@lists.php.net to get a copy of this message
Note that the $_COOKIE variable not will hold multiple cookies with the same name. It is legitimate to set two cookies with the same name to the same host where the sub domain is different. <?php setcookie("testcookie", "value1hostonly", time(), "/", ".example.com", 0, true); setcookie("testcookie", "value2subdom", time(), "/", "subdom.example.com", 0, true); ?> The next request from the browser will have both cookies in the $_SERVER['HTTP_COOKIE'] variable, but only one of them will be found in the $_COOKIE variable. Requests to subdom.example.com will have both cookies, while browser request to example.com or www.example.com only sends the cookie with the "value1hostonly" value. <?php $kaker = explode(";", $_SERVER['HTTP_COOKIE']); foreach($kaker as $val){ $k = explode("=", $val); echo trim($k[0]) . " => " . $k[1]; } // output testcookie => value1hostonly testcookie => value2subdom ?> ---- Server IP: 62.73.196.231 Probable Submitter: 84.215.66.9 ---- Manual Page -- http://www.php.net/manual/en/function.setcookie.php Edit -- https://master.php.net/note/edit/91140 Del: integrated -- https://master.php.net/note/delete/91140/integrated Del: useless -- https://master.php.net/note/delete/91140/useless Del: bad code -- https://master.php.net/note/delete/91140/bad+code Del: spam -- https://master.php.net/note/delete/91140/spam Del: non-english -- https://master.php.net/note/delete/91140/non-english Del: in docs -- https://master.php.net/note/delete/91140/in+docs Del: other reasons-- https://master.php.net/note/delete/91140 Reject -- https://master.php.net/note/reject/91140 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#156051) next »