Welcome Guest, Not a member yet? Register   Sign In
[Session] Session IDs do not match
#1

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.
Reply
#2

(This post was last modified: 09-06-2020, 03:04 AM by InsiteFX.)

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

Refresh the page first then see what you get.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

(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.
Reply
#4

First that I have ever heard of this happening like that.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#5

(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...
Reply




Theme © iAndrew 2016 - Forum software by © MyBB