Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5961563
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:58:56+00:00 2026-05-22T18:58:56+00:00

Hello StackOverflow Community: Here is a tricky situation. Suppose that 20 users are logged-in

  • 0

Hello StackOverflow Community:

Here is a tricky situation. Suppose that 20 users are logged-in to my webapp and I, the admin, (from a different computer and browser) ban 3 of them, how then do I kick out those 3 logged-in users that I just banned? It seems to be a matter of deleting their sessions/cookies, but how do I know which sessions to delete/invalidate and how to access them?

Just so you know, this project is in CakePHP and I’m using Memcache as the engine to store sessions. I already tried an option discussed in the cakephp channel that goes like this:


  1. When user log-ins, his session_id (e.g. sd19eIVasdokja021dnasd) is stored in memcached along with his user id (e.g. the one in db: 323). This way, the user’s db record is associated with his session_id within the server. Some code:
    Cache::write('user_session_id_' . $this->Auth->user('id'), $this->Session->id());

  2. After the model sets the user’s banned column to 1, I lookup if a Memcache key with the user’s id exists, from which I retrieve the session id. I then delete the Memcache key:

    if ($this->save(array('User' => array('id' => $userId, 'banned' => 1)), false)) {
    $userSessionId = Cache::read('user_session_id_' . $userId);
    if ($userSessionId !== false) {
    Cache::delete($userSessionId);
    Cache::delete('user_session_id_' . $userId);
    }
    }

  3. It doesn’t work, the user is still logged-in. I’m very sure I have to destroy/invalidate cookies though, in which case there is probably no way to alter other users cookies, right?


FOLLOWUP AND SOLUTION:

I was able to solve this by following this…
Remotely destroy a session in php (user logs in somewhere else)?

…and also this (a bit pseudo-code within the User model that actually evolved from my point number two above)(Note that my point number one listed above is also needed, due to line six below):

foreach ($bannedUsers as $userId) {  
    if ($this->save(array('User' => array(  
        'id' => $userId,  
        'banned' => 1, 
        'ban_date' => date('Y-m-d H:i:s'))), false)) {  
            $userSessionId = Cache::read('user_session_id_' . $userId);  
            if ($userSessionId !== false) {  
                $Session->id($userSessionId);  
                $Session->write('Auth', '');  
                Cache::delete('user_session_id_' . $userId);  
            }  
    }  
}  
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T18:58:56+00:00Added an answer on May 22, 2026 at 6:58 pm

    You seem to be doing something wrong with your app. The idea of the SESSION/COOKIE system is that the SESSION id stored is matched at the beginning of each request made to the server with the COOKIE that the browser sends. If they don’t match, the app simply exits and shows the logon page. Thus, if you are able to delete the SESSION id correctly, there is no way that a particular user is not logged off unless you are not checking the SESSION/COOKIE match that you should at the first line of every page.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello StackOverflow community, The air.swf file referenced here: http://livedocs.adobe.com/flex/3/html/help.html?content=distributing_apps_3.html used to launch AIR applications
Hello StackOverflow community, I have run into a problem that quite frankly is baffling
Hello stackoverflow community, I am writing a batch file to do some automatic computer
Hello StackOverflow Community, I hope you guys can help me with this here: On
Hello stackoverflow community ! I am trying to figure out how to architect my
Hello StackOverflow community, Using Google App Engine, I wrote a keyToSha256() method within a
Hello StackOverflow'ers, I have a (flex) app that, on the click of a button,
Suppose I have this code: String encoding = UTF-16; String text = [Hello StackOverflow];
Hello StackOverflow community, Is there any way to open a folder in Windows Explorer
Hello StackOverflow community, Is there any way to package the installer for an Adobe

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.