codeigniter session expiration refresh codeigniter session expiration refresh codeigniter codeigniter

codeigniter session expiration refresh


If you are adamant about calling $this->session->sess_destroy(); then you must also call $this->session->sess_create(); BEFORE you try to set session data again, otherwise it will not get set.

Edit: This is if you're using the database to store your sessions. Otherwise, you could re-create a session without manually calling sess_create()


For the latest versions of CodeIgniter including what's currently in the 'develop' branch, you can't call session->set_userdata after session->sess_destroy as already mentioned by another answer. This is because sess_destroy() clears the internal userdata array, including the current session_id which is indirectly required by set_userdata (set_userdata calls sess_write which directly requires the current session_id).

You should see this requirement if you have warnings enabled.


Set $config['sess_time_to_update'] lower than $config['sess_expiration'].

And remove $this->session->sess_destroy(). This function should be the last one called, and even flash variables will no longer be available. If you only want some items destroyed and not all, use unset_userdata().