function session_cache_set in Session Cache API 6
Same name and namespace in other branches
- 8 session_cache.module \session_cache_set()
- 7 session_cache.api.php \session_cache_set()
- 7 session_cache.module \session_cache_set()
Write the supplied data to the user session, whatever the storage mechanism may be.
Parameters
string $bin, unique id eg a string prefixed by the module name:
$data, use NULL to delete the bin; it may be refilled at any time:
File
- ./
session_cache.module, line 27 - session_cache.module
Code
function session_cache_set($bin, $data) {
if (!isset($bin)) {
return;
}
$method = variable_get('session_cache_storage_method', SESSION_CACHE_STORAGE_SESSION);
switch ($method) {
case SESSION_CACHE_STORAGE_COOKIE:
// Tell the browser to return the cookie only via HTTP or HTTPS, to any
// path under the root of this server.
// Don't use "global $cookie_domain", as it may contain the invalid '.localhost'!
$cookie_domain = ini_get('session.cookie_domain');
$serialized_data = $data == NULL ? NULL : serialize($data);
setcookie("Drupal.session_cache.{$bin}", $serialized_data, $data == NULL ? 0 : session_cache_expiration_time(), '/', $cookie_domain, NULL, TRUE);
// Make sure that subsequent session_cache_get() calls get the data
// updated here, not what was in the cookie at the start of the request!
// Note that in array indices '.' are converted to '_'
$_COOKIE["Drupal_session_cache_{$bin}"] = $serialized_data;
return;
case SESSION_CACHE_STORAGE_DB_CORE:
$sid = session_cache_get_sid();
if ($data == NULL) {
cache_clear_all("{$bin}:{$sid}", 'cache_session_cache');
}
else {
cache_set("{$bin}:{$sid}", $data, 'cache_session_cache', session_cache_expiration_time());
}
return;
case SESSION_CACHE_STORAGE_SESSION:
if ($data == NULL) {
unset($_SESSION[$bin]);
return;
}
$_SESSION[$bin] = $data;
return;
default:
module_invoke_all('session_cache_set', $method, $bin, $data);
}
}