4

The users can logout visinting my-site.com/logout by themselves But is there any way Admin can logout other users?

13

If you go to admin/user/user, you can block the user, which will cause them to be logged out. After that, if you want them to be able to login again, you can just immediately unblock them. Also, if you as an admin change a user's password, they will be logged out and will have to use this new password to log back in.

If you want to get fancy, you could do something like this in a custom module as well:

function YOURMODULE_user_operations($form_state = array()) {

  $operations = array(
    'logout' => array(
      'label' => t('Logout the selected users'),
      'callback' => 'YOURMODULE_user_operations_logout',
    ),
  );

  return $operations;

}

function YOURMODULE_user_operations_logout($accounts) {
  foreach ($accounts as $uid) {
    sess_destroy_uid($uid);
  }
}

which would add a "Logout the selected users" option to that menu as well.

| improve this answer | |
  • quite welcome, I added some quick off the cuff fanciness to the answer as well. – Jimajamma Dec 20 '13 at 3:11
  • 6
    I love learning about hooks I have never used. What a simple solution to a common problem. – mpdonadio Dec 20 '13 at 4:23
  • Two quick notes about this. sess_destroy_uid is for Drupal 6. Use drupal_session_destroy_uid for Drupal 7. This won't work with Administration Views in Drupal 7 (haven't tested 6), which use VBO. VBO removed hook_user_operations, so you have to use an action instead. – mpdonadio Feb 11 '14 at 20:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.