CodeIgniter Forums
[Session] Session IDs do not match - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=11)
+--- Thread: [Session] Session IDs do not match (/showthread.php?tid=77470)



[Session] Session IDs do not match - HardyW - 09-05-2020

Suppose I have the following code:
PHP Code:
$session session();
log_message('debug','Session ID: '.session_id());
log_message('debug','Session array: '.var_export($_SESSION,TRUE)); 
 This is after the first call to the php (after a session ID has been renewed) sometimes the output:

DEBUG - 2020-09-05 12:34:36 --> Session ID: 528172rok6phf1ttgu9ucvl3f4pkcqjj
DEBUG - 2020-09-05 12:34:36 --> Session array: array (
  '__ci_last_regenerate' => 1599302009,
  'user_language' => 'de',
  '_ci_previous_url' =>'http://.....',
)
DEBUG - 2020-09-05 12:34:36 --> Session: CodeIgniter\Session\Session::__set_state(array(
  'driver' =>
  CodeIgniter\Session\Handlers\FileHandler::__set_state(array(
    'savePath' => '...',
    'fileHandle' => NULL,
    'filePath' => '...',
    'fileNew' => false,
    'matchIP' => false,
    'fingerprint' => 'd41d8cd98f00b204e9800998ecf8427e',
    'lock' => false,
    'cookiePrefix' => '',
    'cookieDomain' => '',
    'cookiePath' => '/',
    'cookieSecure' => false,
    'cookieName' => 'ci_session',
    'sessionID' => '4gtbbgdn3ig0kcu7ejhee49jil9mhujk',

The lower session ID (sessionID 4gt...) seems to be an older session ID.
Does anybody know why I get two different session IDs?

After the next call the IDs match.


RE: [Session] Session IDs do not match - InsiteFX - 09-06-2020

It could be because cookies do not update until a page refresh has happened.

Refresh the page first then see what you get.


RE: [Session] Session IDs do not match - HardyW - 09-06-2020

(09-06-2020, 03:02 AM)InsiteFX Wrote: It could be because cookies do not update until a page refresh has happened.

Refresh the page first then see what you get.
No, this was not the case. The reason was that the request sent two cookies with the same name "ci_session". And it seems to be that the two statements got their IDs from different cookies.

PS: I did not know that this is possible. Took me a while to find it out.


RE: [Session] Session IDs do not match - InsiteFX - 09-07-2020

First that I have ever heard of this happening like that.


RE: [Session] Session IDs do not match - HardyW - 09-07-2020

(09-07-2020, 12:30 PM)InsiteFX Wrote: First that I have ever heard of this happening like that.
Yep, I did also not imagine this. This was the scenario:

First request was sent to "www.example.com/...". CodeIgniter redirected the request to "example.com/..." via redirect()->to(). By doing so two different cookies were generated with the same name(!) but one for www.example.com and the other one for example.com.
The next request submitted both cookies and the mess started...