function session_cache_get_sid in Session Cache API 7
Same name and namespace in other branches
- 8 session_cache.module \session_cache_get_sid()
- 6 session_cache.module \session_cache_get_sid()
Returns an identifier for the current user session.
Typically only called when a database or file-based storage mechanism is employd.
Return value
int session cache id
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 data to the user session, whatever the storage mechanism may be.
File
- ./
session_cache.module, line 139 - session_cache.module
Code
function session_cache_get_sid() {
global $user;
$sid_source = variable_get('session_cache_sid_source', SESSION_CACHE_COOKIE_FOR_SID);
if ($sid_source == SESSION_CACHE_IP_ADDRESS_FOR_SID) {
// Do we want '::1' for localhost or dots in file names?
$sid = ip_address();
return $sid == '::1' ? 'localhost' : $sid;
}
// SESSION_CACHE_UID_FOR_SID falls back on cookie for anonymous users.
if ($sid_source == SESSION_CACHE_UID_FOR_SID && !empty($user->uid)) {
// Fine if concurrent sessions for the same auth. user are NOT required.
return 'user' . $user->uid;
}
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);
global $cookie_domain;
// .localhost causes problems
$cdom = $cookie_domain == '.localhost' ? ini_get('session.cookie_domain') : $cookie_domain;
// If setcookie() fails, then everything still works, but a new session will
// be created when logging in or out.
setcookie('Drupal.session_cache.sid', $sid, session_cache_expiration_time(), '/', $cdom, NULL, TRUE);
// Need to also set $_COOKIE explicitly, see [#2210329].
$_COOKIE['Drupal_session_cache_sid'] = $sid;
}
else {
$sid = $_COOKIE['Drupal_session_cache_sid'];
}
return $sid;
}