4 * @file src/Core/Session.php
6 namespace Friendica\Core;
8 use Friendica\Core\Session\CacheSessionHandler;
9 use Friendica\Core\Session\DatabaseSessionHandler;
12 * High-level Session service class
14 * @author Hypolite Petovan <hypolite@mrpetovan.com>
18 public static $exists = false;
19 public static $expire = 180000;
21 public static function init()
23 ini_set('session.gc_probability', 50);
24 ini_set('session.use_only_cookies', 1);
25 ini_set('session.cookie_httponly', 1);
27 if (Config::get('system', 'ssl_policy') == SSL_POLICY_FULL) {
28 ini_set('session.cookie_secure', 1);
31 $session_handler = Config::get('system', 'session_handler', 'database');
32 if ($session_handler != 'native') {
33 if ($session_handler == 'cache' && Config::get('system', 'cache_driver', 'database') != 'database') {
34 $SessionHandler = new CacheSessionHandler();
36 $SessionHandler = new DatabaseSessionHandler();
39 session_set_save_handler($SessionHandler);
43 public static function exists($name)
45 return isset($_SESSION[$name]);
49 * Retrieves a key from the session super global or the defaults if the key is missing or the value is falsy.
51 * Handle the case where session_start() hasn't been called and the super global isn't available.
54 * @param mixed $defaults
57 public static function get($name, $defaults = null)
59 if (isset($_SESSION)) {
60 $return = defaults($_SESSION, $name, $defaults);
68 public static function set($name, $value)
70 $_SESSION[$name] = $value;