Losing CodeIgniter Sessions
I had a scenario earlier today where I was setting a session using the CodeIgniter Session library, it was being set fine but then as soon as I navigated to another page it was being lost.
After much research and testing it turns out it was due to the fact my session name contained an underscore. Removing the underscore then resolved the issue:
$this->session->set_userdata('my_session_name', 'My Session Data');
Became:
$this->session->set_userdata('mysessionname', 'My Session Data');
I’m not sure why this occured and I’m suprised it’s not mentioned anywhere in the CodeIgniter user guide. Anyway, I hope that this helps someone who is experiencing similar problems with regards to losing session data.
On a side note. If you redirect from http://www.example.com to http://example.com the session will change and all data will go.
this solved in 2.1.3 released
dunno but i still have session lost…. this make my DB become corrupt.. when update based on session
thanks,it helped me a lot.
Hi Steve, thanks for your help, I am doing a application and looking one respond for “session lost in codeigniter”, and your solution work fine for me!
thanks!
Gerardo
Thanks. This worked for me. Though instead of just removing underscores, I replaced them with dashes. So far, it seems to be working fine.
Thank, this helped me. And for anybody seeing this looking for answers, removing the underscore from the cookie name (ci_session) to (cisession) can also fix problems.