]> git.mxchange.org Git - friendica.git/blob - src/Core/Session/Native.php
Overwrite constructor of Memory session handling so no session ini-setting in backend...
[friendica.git] / src / Core / Session / Native.php
1 <?php
2
3 namespace Friendica\Core\Session;
4
5 use Friendica\Core\Config\Configuration;
6 use Friendica\App;
7 use Friendica\Model\User\Cookie;
8
9 /**
10  * The native Session class which uses the PHP internal Session function
11  */
12 class Native implements ISession
13 {
14         /** @var Cookie */
15         protected $cookie;
16
17         public function __construct(Configuration $config, Cookie $cookie)
18         {
19                 ini_set('session.gc_probability', 50);
20                 ini_set('session.use_only_cookies', 1);
21                 ini_set('session.cookie_httponly', 1);
22
23                 if ($config->get('system', 'ssl_policy') == App\BaseURL::SSL_POLICY_FULL) {
24                         ini_set('session.cookie_secure', 1);
25                 }
26
27                 $this->cookie = $cookie;
28         }
29
30         /**
31          * {@inheritDoc}
32          */
33         public function start()
34         {
35                 session_start();
36                 return $this;
37         }
38
39         /**
40          * {@inheritDoc}}
41          */
42         public function exists(string $name)
43         {
44                 return isset($_SESSION[$name]);
45         }
46
47         /**
48          * {@inheritDoc}
49          */
50         public function get(string $name, $defaults = null)
51         {
52                 return $_SESSION[$name] ?? $defaults;
53         }
54
55         /**
56          * {@inheritDoc}
57          */
58         public function set(string $name, $value)
59         {
60                 $_SESSION[$name] = $value;
61         }
62
63         /**
64          * {@inheritDoc}
65          */
66         public function setMultiple(array $values)
67         {
68                 $_SESSION = $values + $_SESSION;
69         }
70
71         /**
72          * {@inheritDoc}
73          */
74         public function remove(string $name)
75         {
76                 unset($_SESSION[$name]);
77         }
78
79         /**
80          * {@inheritDoc}
81          */
82         public function clear()
83         {
84                 $_SESSION = [];
85         }
86
87         /**
88          * @brief Kills the "Friendica" cookie and all session data
89          */
90         public function delete()
91         {
92                 $this->cookie->clear();
93                 $_SESSION = [];
94         }
95 }