Losing CodeIgniter Sessions

May 21st, 2010 - Posted by Steve Marks to PHP, Web Development.

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');


$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.

This entry was posted on Friday, May 21st, 2010 at 4:52 pm by +Steve Marks and is filed under PHP, Web Development. You can follow any responses to this entry through the RSS 2.0 feed.

Fear not, we won't publish this

Comments (7)
  1. Jacob says:

    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.

  2. red says:

    this solved in 2.1.3 released

  3. hendra says:

    dunno but i still have session lost…. this make my DB become corrupt.. when update based on session

  4. alin says:

    thanks,it helped me a lot.

  5. Gerardo says:

    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!


  6. anon says:

    Thanks. This worked for me. Though instead of just removing underscores, I replaced them with dashes. So far, it seems to be working fine.

  7. douglas says:

    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.