简体   繁体   中英

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

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.

Use the sess_destroy() method instead:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM