This constructor is included in case it is needed in the the
future. Including it now allows us to write parent::__construct() in
the subclasses of this class.
protected __construct ( ) |
protected function __construct() { /* Call the parent constructor in case it should become * necessary in the future. */ parent::__construct(); /* Initialize the php session handling. * * If session_id() returns a blank string, then we need * to call session start. Otherwise the session is already * started, and we should avoid calling session_start(). */ if (session_id() === '') { $config = SimpleSAML_Configuration::getInstance(); $cookiepath = $config->getBoolean('session.phpsession.limitedpath', FALSE) ? '/' . $config->getBaseURL() : '/'; session_set_cookie_params(0, $cookiepath, NULL, SimpleSAML_Utilities::isHTTPS()); $cookiename = $config->getString('session.phpsession.cookiename', NULL); if (!empty($cookiename)) { session_name($cookiename); } $savepath = $config->getString('session.phpsession.savepath', NULL); if (!empty($savepath)) { session_save_path($savepath); } if (!array_key_exists(session_name(), $_COOKIE)) { /* Session cookie unset - session id not set. Generate new (secure) session id. */ session_id(SimpleSAML_Utilities::stringToHex(SimpleSAML_Utilities::generateRandomBytes(16))); } session_start(); } }
protected function __construct() { /* Call the parent constructor in case it should become * necessary in the future. */ parent::__construct(); /* Initialize the php session handling. * * If session_id() returns a blank string, then we need * to call session start. Otherwise the session is already * started, and we should avoid calling session_start(). */ if (session_id() === '') { $config = SimpleSAML_Configuration::getInstance(); $params = $this->getCookieParams(); $version = explode('.', PHP_VERSION); if ((int) $version[0] === 5 && (int) $version[1] < 2) { session_set_cookie_params($params['lifetime'], $params['path'], $params['domain'], $params['secure']); } else { session_set_cookie_params($params['lifetime'], $params['path'], $params['domain'], $params['secure'], $params['httponly']); } $this->cookie_name = $config->getString('session.phpsession.cookiename', NULL); if (!empty($this->cookie_name)) { session_name($this->cookie_name); } else { $this->cookie_name = session_name(); } $savepath = $config->getString('session.phpsession.savepath', NULL); if (!empty($savepath)) { session_save_path($savepath); } } }
/** * This constructor initializes the session id based on what we receive in a cookie. We create a new session id and * set a cookie with this id if we don't have a session id. */ protected function __construct() { // call the constructor in the base class in case it should become necessary in the future parent::__construct(); $config = SimpleSAML_Configuration::getInstance(); $this->cookie_name = $config->getString('session.cookie.name', 'SimpleSAMLSessionID'); }
protected function __construct() { /* Call the constructor in the base class in case it should * become necessary in the future. */ parent::__construct(); /* Attempt to retrieve the session id from the cookie. */ if (array_key_exists('SimpleSAMLSessionID', $_COOKIE)) { $this->session_id = $_COOKIE['SimpleSAMLSessionID']; } /* Check if we have a valid session id. */ if (self::isValidSessionID($this->session_id)) { /* We are done now if it was valid. */ return; } /* We don't have a valid session. Create a new session id. */ $this->session_id = self::createSessionID(); setcookie('SimpleSAMLSessionID', $this->session_id, 0, '/', NULL, self::secureCookie()); }
protected function __construct() { /* Call the parent constructor in case it should become * necessary in the future. */ parent::__construct(); /* Initialize the php session handling. * * If session_id() returns a blank string, then we need * to call session start. Otherwise the session is already * started, and we should avoid calling session_start(). */ if (session_id() === '') { $config = SimpleSAML_Configuration::getInstance(); $params = $this->getCookieParams(); $version = explode('.', PHP_VERSION); if ((int) $version[0] === 5 && (int) $version[1] < 2) { session_set_cookie_params($params['lifetime'], $params['path'], $params['domain'], $params['secure']); } else { session_set_cookie_params($params['lifetime'], $params['path'], $params['domain'], $params['secure'], $params['httponly']); } $cookiename = $config->getString('session.phpsession.cookiename', NULL); if (!empty($cookiename)) { session_name($cookiename); } $savepath = $config->getString('session.phpsession.savepath', NULL); if (!empty($savepath)) { session_save_path($savepath); } if (!array_key_exists(session_name(), $_COOKIE)) { if (headers_sent()) { throw new SimpleSAML_Error_Exception('Cannot create new session - headers already sent.'); } /* Session cookie unset - session id not set. Generate new (secure) session id. */ session_id(SimpleSAML_Utilities::stringToHex(SimpleSAML_Utilities::generateRandomBytes(16))); } session_start(); } }
protected function __construct() { /* Call the constructor in the base class in case it should * become necessary in the future. */ parent::__construct(); /* Attempt to retrieve the session id from the cookie. */ if (array_key_exists('SimpleSAMLSessionID', $_COOKIE)) { $this->session_id = $_COOKIE['SimpleSAMLSessionID']; } /* We need to create a new session. */ if (headers_sent()) { throw new SimpleSAML_Error_Exception('Cannot create new session - headers already sent.'); } /* Check if we have a valid session id. */ if (self::isValidSessionID($this->session_id)) { /* We are done now if it was valid. */ return; } /* We don't have a valid session. Create a new session id. */ $this->session_id = self::createSessionID(); $this->setCookie('SimpleSAMLSessionID', $this->session_id); }
/** * Initialize the PHP session handling. This constructor is protected because it should only be called from * SimpleSAML_SessionHandler::createSessionHandler(...). */ protected function __construct() { // call the parent constructor in case it should become necessary in the future parent::__construct(); $config = SimpleSAML_Configuration::getInstance(); $this->cookie_name = $config->getString('session.phpsession.cookiename', null); if (function_exists('session_status') && defined('PHP_SESSION_ACTIVE')) { // PHP >= 5.4 $previous_session = session_status() === PHP_SESSION_ACTIVE; } else { $previous_session = session_id() !== '' && session_name() !== $this->cookie_name; } if ($previous_session) { if (session_name() === $this->cookie_name || $this->cookie_name === null) { SimpleSAML\Logger::warning('There is already a PHP session with the same name as SimpleSAMLphp\'s session, or the ' . "'session.phpsession.cookiename' configuration option is not set. Make sure to set " . "SimpleSAMLphp's cookie name with a value not used by any other applications."); } /* * We shouldn't have a session at this point, so it might be an application session. Save the details to * retrieve it later and commit. */ $this->previous_session['cookie_params'] = session_get_cookie_params(); $this->previous_session['id'] = session_id(); $this->previous_session['name'] = session_name(); session_write_close(); } if (!empty($this->cookie_name)) { session_name($this->cookie_name); } else { $this->cookie_name = session_name(); } $params = $this->getCookieParams(); session_set_cookie_params($params['lifetime'], $params['path'], $params['domain'], $params['secure'], $params['httponly']); $savepath = $config->getString('session.phpsession.savepath', null); if (!empty($savepath)) { session_save_path($savepath); } }