note 101734 added to function.session-id

From: Date: Fri, 07 Jan 2011 19:17:08 +0000
Subject: note 101734 added to function.session-id
Groups: php.notes 
Request: Send a blank email to php-notes+get-175521@lists.php.net to get a copy of this message
I was perplexed by inconsistent results with the session ID depending on whether I retrieve it using SID, COOKIE, or session_id(). I have found that session_id() is the most reliable method, whereas SID and COOKIE["PHPSESSIONID"] are sometimes undefined. I used this simple script to quickly test the problem on my servers: <?php $a = session_id(); if(empty($a)) session_start(); echo "SID: ".SID."<br>session_id(): ".session_id()."<br>COOKIE: ".$_COOKIE["PHPSESSID"]; ?> Regardless of browser I see the COOKIE undefined on the first load and the other two defined, then SID is empty on subsequent reloads and COOKIE is defined, but session_id() is always defined. If I insert the session_regenerate_id() method that jeff_zamrzla gives below the refresh the page, I get a new session_id() but the COOKIE value is initially the prior session_id() until I hit refresh a second time. So again, session_id() proves to be the most reliable method. It's probably not a bug since I found the behaviour to be consistent in PHP versions 5.2.14, 5.3.3 and 5.3.4, but I can't figure what I'm missing and hopefully this will help others who run into this. ---- Server IP: 66.207.199.35 Probable Submitter: 76.11.1.197 ---- Manual Page -- http://www.php.net/manual/en/function.session-id.php Edit -- https://master.php.net/note/edit/101734 Del: integrated -- https://master.php.net/note/delete/101734/integrated Del: useless -- https://master.php.net/note/delete/101734/useless Del: bad code -- https://master.php.net/note/delete/101734/bad+code Del: spam -- https://master.php.net/note/delete/101734/spam Del: non-english -- https://master.php.net/note/delete/101734/non-english Del: in docs -- https://master.php.net/note/delete/101734/in+docs Del: other reasons-- https://master.php.net/note/delete/101734 Reject -- https://master.php.net/note/reject/101734 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#175521) next »