对特定用户执行查询/任务

I got a user system, with session for both their username and ID. I also got a field in my users table named user_locked which determines if the user's account is locked or not (if it's locked; they can't log in).

Recently I added a feature on my site where it allows me to lock users easily by one click, and I then got the idea: is it possible to force that specific user to get logged out (make his/her session/cookies get destroyed) while leaving everyone elses unharmed?

Is it possible? If it is, how would I do?

Thanks.

My approach would be:

  1. User logs in
  2. You start a session for him and store whatever session variables you want
  3. You store this session's ID in a table at your database with user id/username info
  4. Whenever you want to destroy his session and log him out you follow this routine:

    // old_session_id will be retrieved from your database table for
    // this current user that you want to force log off
    session_id($old_session_id);
    session_start();
    session_destroy();
    

Destroy php session remotely