You are here

function session_cache_get_sid in Session Cache API 8

Same name and namespace in other branches
  1. 6 session_cache.module \session_cache_get_sid()
  2. 7 session_cache.module \session_cache_get_sid()

Returns an identifier for the current user session.

Typically only called when a database storage mechanism is used.

Return value

sid

4 calls to session_cache_get_sid()
session_cache_file_session_cache_get in session_cache_file/session_cache_file.module
Implements hook_session_cache_get().
session_cache_file_session_cache_set in session_cache_file/session_cache_file.module
Implements hook_session_cache_set().
session_cache_get in ./session_cache.module
Read data from the user session, given its bin id.
session_cache_set in ./session_cache.module
Write the supplied data to the user session, whatever the storage mechanism may be.

File

./session_cache.module, line 121
session_cache.module

Code

function session_cache_get_sid() {
  global $user;
  if (!empty($user->uid) && config('session_cache.settings')
    ->get('use_uid_as_sid')) {
    return 'user' . $user->uid;

    // good if concurrent sessions for the same authenticated user are NOT required
  }
  if (empty($_COOKIE['Drupal_session_cache_sid'])) {

    // Don't use core's session id. Security not a problem, so keep it short.
    $sid = drupal_substr(session_id(), 0, 12);

    // If setcookie() fails, then everything still works, but a new session will
    // be created when logging in or out.
    // Don't use "global $cookie_domain", as it may contain '.localhost', which
    // is invalid!
    $cookie_domain = ini_get('session.cookie_domain');
    setcookie('Drupal.session_cache.sid', $sid, session_cache_expiration_time(), '/', $cookie_domain, NULL, TRUE);
  }
  else {
    $sid = $_COOKIE['Drupal_session_cache_sid'];
  }
  return $sid;
}