You are here

function bakery_user_logout in Bakery Single Sign-On System 6.2

Same name and namespace in other branches
  1. 8.2 bakery.module \bakery_user_logout()
  2. 6 bakery.module \bakery_user_logout()
  3. 7.4 bakery.module \bakery_user_logout()
  4. 7.2 bakery.module \bakery_user_logout()
  5. 7.3 bakery.module \bakery_user_logout()

Custom logout function modified from user_logout.

1 call to bakery_user_logout()
_bakery_taste_chocolatechip_cookie in ./bakery.module
Test identification cookie.

File

./bakery.module, line 1634

Code

function bakery_user_logout() {
  global $user;
  watchdog('user', 'Session closed for %name.', array(
    '%name' => $user->name,
  ));

  // Destroy the current session:
  session_destroy();
  $edit = array();
  user_module_invoke('logout', $edit, $user);

  // Load the anonymous user
  $user = drupal_anonymous_user();

  // We want to redirect the user to his original destination.
  $get = $_GET;
  $destination = !empty($get['q']) ? $get['q'] : '';
  unset($get['q']);

  // We append a GET parameter so that the browser reloads the page.
  $get['no_cache'] = time();

  // Build the URL we'll redirect to. We set alias to TRUE so as not to try and
  // hit the unavailable database looking for an alias.
  $url = url($destination, array(
    'query' => $get,
    'absolute' => TRUE,
    'alias' => TRUE,
  ));

  // Remove newlines from the URL to avoid header injection attacks.
  $url = str_replace(array(
    "\n",
    "\r",
  ), '', $url);

  // We can't use drupal_goto because it assumes it's in a later boot phase. Set
  // the status code to be temporary redirect because of the no_cache time.
  header('Location: ' . $url, TRUE, 307);
  exit;
}