1.20.x session.inc backdrop_session_start()

Starts a session forcefully, preserving already set session data.

Related topics

File

includes/session.inc, line 285
User session handling functions.

Code

function backdrop_session_start() {
  // Command line clients do not support cookies nor sessions.
  if (!backdrop_session_started() && !backdrop_is_cli()) {
    // Save current session data before starting it, as PHP will destroy it.
    $session_data = isset($_SESSION) ? $_SESSION : NULL;

    session_start();
    backdrop_session_started(TRUE);

    // Restore session data.
    if (!empty($session_data)) {
      $_SESSION += $session_data;
    }
  }
}