CodeIgniter Forums
Help! Unexpected session behaviour - constantly reloading - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Help! Unexpected session behaviour - constantly reloading (/showthread.php?tid=52087)



Help! Unexpected session behaviour - constantly reloading - El Forum - 05-29-2012

[eluser]Unknown[/eluser]
Hi,

I'm having trouble using the session library. For some reason, my sessions simply do not last, and are reloaded with the page. I'm monitoring the session_id after login, and every time I refresh the page it changes, rather than staying the same. Subsequently any information I stored in the session is gone, and the session is useless. I managed to find a thread created in 2010 where this problem was prominent, however I wasn't able to resolve the issue and I can no longer find the thread.

I did however read that the issue was with using localhost, so I am now using 127.0.0.1 (apparently a period or two is required in the domain). I do not have the database enabled for these sessions.

Can anyone help?

config: http://pastie.org/3989153

Sample code:
Code:
$this->session->set_userdata('test1', $test1);
$this->session->set_userdata('test2', $test2);

// redirect the user to the home page

// code for next page, works fine upon the initial redirect, then
// breaks when page is refreshed. test1 no longer exists and the session_id
// changes for each page refresh
echo $this->session->userdata('test1');
echo $this->session->userdata('session_id')



Help! Unexpected session behaviour - constantly reloading - El Forum - 05-29-2012

[eluser]Unknown[/eluser]
Got a working test case together, and manage to locate where my problem was in production. Problem solved, this thread may be locked.


Help! Unexpected session behaviour - constantly reloading - El Forum - 05-29-2012

[eluser]weboap[/eluser]
http://ellislab.com/codeigniter/user-guide/libraries/sessions.html

Quote:
...
When a page is loaded, the session class will check to see if valid session data exists in the user's session cookie. If sessions data does not exist (or if it has expired) a new session will be created and saved in the cookie. If a session does exist, its information will be updated and the cookie will be updated. With each update, the session_id will be regenerated.
...



Help! Unexpected session behaviour - constantly reloading - El Forum - 05-29-2012

[eluser]Aken[/eluser]
weboap, you should use [ quote ] instead of [ code ] for stuff like that.

aaronds, you should post what the problem and solution was in the future, in case someone else has a similar situation and is searching for an answer.