function drupal_session_commit in Drupal 7
Commits the current session, if necessary.
If an anonymous user already have an empty session, destroy it.
4 calls to drupal_session_commit()
- ajax_footer in includes/
ajax.inc - Performs end-of-Ajax-request tasks.
- drupal_exit in includes/
common.inc - Performs end-of-request tasks.
- drupal_page_footer in includes/
common.inc - Performs end-of-request tasks.
- _session_test_id in modules/
simpletest/ tests/ session_test.module - Menu callback: print the current session ID.
1 string reference to 'drupal_session_commit'
- ajax_footer in includes/
ajax.inc - Performs end-of-Ajax-request tasks.
File
- includes/
session.inc, line 316 - User session handling functions.
Code
function drupal_session_commit() {
global $user, $is_https;
if (!drupal_save_session()) {
// We don't have anything to do if we are not allowed to save the session.
return;
}
if (empty($user->uid) && empty($_SESSION)) {
// There is no session data to store, destroy the session if it was
// previously started.
if (drupal_session_started()) {
session_destroy();
}
}
else {
// There is session data to store. Start the session if it is not already
// started.
if (!drupal_session_started()) {
drupal_session_start();
if ($is_https && variable_get('https', FALSE)) {
$insecure_session_name = substr(session_name(), 1);
$params = session_get_cookie_params();
$expire = $params['lifetime'] ? REQUEST_TIME + $params['lifetime'] : 0;
$options = array(
'expires' => $expire,
'path' => $params['path'],
'domain' => $params['domain'],
'secure' => FALSE,
'httponly' => $params['httponly'],
);
drupal_setcookie($insecure_session_name, $_COOKIE[$insecure_session_name], $options);
}
}
// Write the session data.
session_write_close();
}
}