]> git.mxchange.org Git - friendica.git/blob - src/Core/Session.php
Better handling of empty content
[friendica.git] / src / Core / Session.php
1 <?php
2
3 /**
4  * @file src/Core/Session.php
5  */
6 namespace Friendica\Core;
7
8 use Friendica\Core\Session\CacheSessionHandler;
9 use Friendica\Core\Session\DatabaseSessionHandler;
10
11 /**
12  * High-level Session service class
13  *
14  * @author Hypolite Petovan <mrpetovan@gmail.com>
15  */
16 class Session
17 {
18         public static $exists = false;
19         public static $expire = 180000;
20
21         public static function init()
22         {
23                 ini_set('session.gc_probability', 50);
24                 ini_set('session.use_only_cookies', 1);
25                 ini_set('session.cookie_httponly', 1);
26
27                 if (Config::get('system', 'ssl_policy') == SSL_POLICY_FULL) {
28                         ini_set('session.cookie_secure', 1);
29                 }
30
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();
35                         } else {
36                                 $SessionHandler = new DatabaseSessionHandler();
37                         }
38
39                         session_set_save_handler($SessionHandler);
40                 }
41         }
42
43         public static function exists($name)
44         {
45                 return isset($_SESSION[$name]);
46         }
47
48         public static function get($name)
49         {
50                 return defaults($_SESSION, $name, null);
51         }
52
53         public static function set($name, $value)
54         {
55                 $_SESSION[$name] = $value;
56         }
57 }