1

I need to logout a specific user programmatically whose uid is known to me.

I think I need to destroy the session. Is there any table in drupal store that value?

5

Use drupal_session_destroy_uid function.

Ends a specific user's session(s).

Example:

drupal_session_destroy_uid($uid_to_logout);
1

I used

\Drupal::service('session_manager')->delete($uid);

for D8

0

You can condition in this code to logout user

// Programmatically logs out the current user
global $user;
$tmp = NULL;
session_destroy();
user_module_invoke('logout', $tmp, $user);
$user = drupal_anonymous_user(); //or any user you get from database 

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.