function user_logout

user_logout()

Logs the current user out.

File

core/modules/user/user.module, line 1391
Enables the user registration and login system.

Code

function user_logout() {
  $user = \Drupal::currentUser();

  \Drupal::logger('user')->notice('Session closed for %name.', array('%name' => $user->getAccountName()));

  \Drupal::moduleHandler()->invokeAll('user_logout', array($user));

  // Destroy the current session, and reset $user to the anonymous user.
  // Note: In Symfony the session is intended to be destroyed with
  // Session::invalidate(). Regrettably this method is currently broken and may
  // lead to the creation of spurious session records in the database.
  // @see https://github.com/symfony/symfony/issues/12375
  \Drupal::service('session_manager')->destroy();
  $user->setAccount(new AnonymousUserSession());
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!modules!user!user.module/function/user_logout/8.1.x