]> git.mxchange.org Git - friendica.git/blob - src/Core/Session.php
Line endings are converted to unix style
[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\DatabaseSessionHandler;
9 use Friendica\Core\Session\MemcacheSessionHandler;
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                 if (!Config::get('system', 'disable_database_session')) {
32                         $memcache = Cache::memcache();
33                         if (is_object($memcache)) {
34                                 $SessionHandler = new MemcacheSessionHandler($memcache);
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 }