Welcome Guest, Not a member yet? Register   Sign In
Saving Session Data to a Database
#1

[eluser]ignitian[/eluser]
Do i need to manage the table on user logout ?

Code:
function logout()
{
  $this->db->delete('ci_sessions', array('session_id' => $this->session->userdata('session_id')));
}
#2

[eluser]Nick_MyShuitings[/eluser]
I don't believe that you do. If you call $this->session->unset_userdata('session_id'); that should take care of the DB if you are using the db for your sessions.
#3

[eluser]ignitian[/eluser]
$this->session->unset_userdata(‘session_id’);

A PHP Error was encountered

Severity: Notice

Message: Undefined index: session_id

Filename: libraries/Session.php
#4

[eluser]Nick_MyShuitings[/eluser]
hmmm... if that is not set, then how does that logout function work... since it would return a false if the index didn't exist.

Have you tried checking how the main auth libraries do it? tank? ion? redux etc?
#5

[eluser]ignitian[/eluser]
Actually $this->session->sess_destroy(); dont delete the record in the ci_sessions table, it only unset user_data field and keep the session_id record.

I guess that is correct. It keep session alive until timeout setting.
#6

[eluser]cideveloper[/eluser]
Code:
$this->session->sess_destroy();

Does delete the row from the DB.

So when the user logs out you can just call $this->session->sess_destroy(); in your controller. Right at the end. Just remember one thing. If you log the user out and destroy his session and then redirect them to another page and have sessions auto-loading, another session will be created.
#7

[eluser]ignitian[/eluser]
thank you !




Theme © iAndrew 2016 - Forum software by © MyBB