WorryFree Computers   »   [go: up one dir, main page]

Force log out online users

Hi,

How can I force all online users to log out or how can I log out all online users ?

Regards,

  • You can take this code.

    Just foreach() the online users and apply the mentioned code, e.g.:

    elgg_call(ELGG_IGNORE_ACCESS, function () use (&$users) {
    
        foreach ($users as $user) {
               _elgg_services()->persistentLogin->removePersistentLogin();
               
               $old_msg = _elgg_services()->session->get(SystemMessagesService::SESSION_KEY, []);
    
              _elgg_services()->session->invalidate();
    
              _elgg_services()->session_manager->getLoggedInUser() = null;
    
              _elgg_services()->set(SystemMessagesService::SESSION_KEY, $old_msg);
    
             _elgg_services()->events->triggerAfter('logout', 'user', $user);
    
        }
    
        return true;
    
    });
  • @Nikolai

    That wouldn't work as the session (and session manager) only apply to the logged in user. There is no way that those services can touch other sessions (luckily).

    @Hermand

    What is your goal? If you wish to perform some maintenance to the server and don't want to have any users only. Simply enable Maintenance mode from the admin side.

    With a bit of programming you can truncate the users_sessions table and therefor nobody will be logged in anymore (maybe also truncate the users_remember_me_cookies table to not automatically let users log back in who have Remember me enabled)

  • @jeabakker and @rivervanrain thanks a a lot I will simply enable Maintenance mode from the admin side.

Beginning Developers

Beginning Developers

This space is for newcomers, who wish to build a new plugin or to customize an existing one to their liking