Error message

You are browsing documentation for drupal 7.x, which is not supported anymore. Read the updated version of this page for drupal 11.x (the latest version).

function drupal_session_start

Starts a session forcefully, preserving already set session data.

Related topics

PHP wrapper functions
Functions that are wrappers or custom implementations of PHP functions.
5 calls to drupal_session_start()
drupal_session_commit in includes/session.inc
Commits the current session, if necessary.
drupal_session_initialize in includes/session.inc
Initializes the session handler, starting a session if needed.
drupal_session_regenerate in includes/session.inc
Called when an anonymous user becomes authenticated or vice-versa.
update.php in ./update.php
Administrative page for handling updates from one Drupal version to another.
_drupal_session_regenerate_existing in includes/session.inc
Regenerates an existing session.

File

includes/session.inc, line 284

Code

function drupal_session_start () {
 // Command line clients do not support cookies nor sessions.
 if (!drupal_session_started () && !drupal_is_cli ()) {
 // Save current session data before starting it, as PHP will destroy it.
 $session_data = isset($_SESSION) ? $_SESSION : NULL;
 // Apply any overrides to the session cookie params.
 $params = $original_params = session_get_cookie_params ();
 // PHP settings for samesite will be handled by _drupal_cookie_params().
 unset($params['samesite']);
 $params = _drupal_cookie_params ($params);
 if ($params !== $original_params) {
 if (\PHP_VERSION_ID >= 70300) {
 session_set_cookie_params ($params);
 }
 else {
 session_set_cookie_params ($params['lifetime'], $params['path'], $params['domain'], $params['secure'], $params['httponly']);
 }
 }
 session_start ();
 drupal_session_started (TRUE);
 // Restore session data.
 if (!empty($session_data)) {
 $_SESSION += $session_data;
 }
 }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.