Afshin
Afshin

Reputation: 2437

force a specific user to logout in codeigniter with destroying his session

I want to force a user to logout when I change it's status to 'inactive' using session in codeigniter.

I used the method below, but it destroyed my own session:

function deactivate($user_Id)
{
    $this->session->unset_userdata(array('user_Id' => $user_Id));
}

Upvotes: 3

Views: 2182

Answers (2)

japh
japh

Reputation: 145

I happened to need this feature implemented and here is how I did it:

  1. record user session id as last_active_session in db after login
  2. find that session id and delete it from session table when this user is banned or anything.

You can also use this to prevent concurrent login such as the last successful login user bump the previous one.

Upvotes: 3

Terry Harvey
Terry Harvey

Reputation: 9444

Use the sess_destroy() method instead:

function deactivate() {
    $this->session->sess_destroy();
}

Upvotes: 0

Related Questions