W3cubDocs

/Drupal 8

public function SessionManager::destroy

public SessionManager::destroy()

Destroys the current session and removes session cookies.

Overrides SessionManagerInterface::destroy

File

core/lib/Drupal/Core/Session/SessionManager.php, line 254

Class

SessionManager
Manages user sessions.

Namespace

Drupal\Core\Session

Code

public function destroy() {
  session_destroy();

  // Unset the session cookies.
  $session_name = $this->getName();
  $cookies = $this->requestStack->getCurrentRequest()->cookies;
  if ($cookies->has($session_name)) {
    $params = session_get_cookie_params();
    setcookie($session_name, '', REQUEST_TIME - 3600, $params['path'], $params['domain'], $params['secure'], $params['httponly']);
    $cookies->remove($session_name);
  }
}

© 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!lib!Drupal!Core!Session!SessionManager.php/function/SessionManager::destroy/8.1.x