X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FCore%2FSession.php;h=d9143c8809e1b1b8df215238fd3cd3585e24ffe8;hb=f786e8984f1bd61a617f00a3e312181846ab40dd;hp=b5c09f745b27a549f637f9793ce849deac64f8e4;hpb=3a7dd5e8916a1886129e43e34f9b7e8f20eebf01;p=friendica.git diff --git a/src/Core/Session.php b/src/Core/Session.php index b5c09f745b..d9143c8809 100644 --- a/src/Core/Session.php +++ b/src/Core/Session.php @@ -1,57 +1,72 @@ - - */ -class Session -{ - public static $exists = false; - public static $expire = 180000; - - public static function init() - { - ini_set('session.gc_probability', 50); - ini_set('session.use_only_cookies', 1); - ini_set('session.cookie_httponly', 1); - - if (Config::get('system', 'ssl_policy') == SSL_POLICY_FULL) { - ini_set('session.cookie_secure', 1); - } - - if (!Config::get('system', 'disable_database_session')) { - $memcache = Cache::memcache(); - if (is_object($memcache)) { - $SessionHandler = new MemcacheSessionHandler($memcache); - } else { - $SessionHandler = new DatabaseSessionHandler(); - } - - session_set_save_handler($SessionHandler); - } - } - - public static function exists($name) - { - return isset($_SESSION[$name]); - } - - public static function get($name) - { - return defaults($_SESSION, $name, null); - } - - public static function set($name, $value) - { - $_SESSION[$name] = $value; - } -} + + */ +class Session +{ + public static $exists = false; + public static $expire = 180000; + + public static function init() + { + ini_set('session.gc_probability', 50); + ini_set('session.use_only_cookies', 1); + ini_set('session.cookie_httponly', 1); + + if (Config::get('system', 'ssl_policy') == SSL_POLICY_FULL) { + ini_set('session.cookie_secure', 1); + } + + $session_handler = Config::get('system', 'session_handler', 'database'); + if ($session_handler != 'native') { + if ($session_handler == 'cache' && Config::get('system', 'cache_driver', 'database') != 'database') { + $SessionHandler = new CacheSessionHandler(); + } else { + $SessionHandler = new DatabaseSessionHandler(); + } + + session_set_save_handler($SessionHandler); + } + } + + public static function exists($name) + { + return isset($_SESSION[$name]); + } + + /** + * Retrieves a key from the session super global or the defaults if the key is missing or the value is falsy. + * + * Handle the case where session_start() hasn't been called and the super global isn't available. + * + * @param string $name + * @param mixed $defaults + * @return mixed + */ + public static function get($name, $defaults = null) + { + if (isset($_SESSION)) { + $return = defaults($_SESSION, $name, $defaults); + } else { + $return = $defaults; + } + + return $return; + } + + public static function set($name, $value) + { + $_SESSION[$name] = $value; + } +}