Rev 571 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 571 | Rev 585 | ||
---|---|---|---|
Line 95... | Line 95... | ||
95 | } |
95 | } |
96 | 96 | ||
97 | public function getValue($name, $default = NULL) { |
97 | public function getValue($name, $default = NULL) { |
98 | if (isset($this->cacheSetValues[$name])) return self::decrypt($this->cacheSetValues[$name], $this->secret); |
98 | if (isset($this->cacheSetValues[$name])) return self::decrypt($this->cacheSetValues[$name], $this->secret); |
99 | 99 | ||
100 | if (!isset($_COOKIE[session_name()])) return $default; // GDPR: Only start a session when we really need one |
100 | if (!$this->isActive()) return $default; // GDPR: Only start a session when we really need one |
101 | $this->sessionSafeStart(); |
101 | $this->sessionSafeStart(); |
102 | OIDplus::cookieUtils()->setcookie(session_name(),session_id(),time()+$this->sessionLifetime); |
102 | OIDplus::cookieUtils()->setcookie(session_name(),session_id(),time()+$this->sessionLifetime); |
103 | 103 | ||
104 | if (!isset($_SESSION[$name])) return $default; |
104 | if (!isset($_SESSION[$name])) return $default; |
105 | return self::decrypt($_SESSION[$name], $this->secret); |
105 | return self::decrypt($_SESSION[$name], $this->secret); |
106 | } |
106 | } |
107 | 107 | ||
108 | public function exists($name) { |
108 | public function exists($name) { |
109 | if (isset($this->cacheSetValues[$name])) return true; |
109 | if (isset($this->cacheSetValues[$name])) return true; |
110 | 110 | ||
111 | if (!isset($_COOKIE[session_name()])) return false; // GDPR: Only start a session when we really need one |
111 | if (!$this->isActive()) return false; // GDPR: Only start a session when we really need one |
112 | $this->sessionSafeStart(); |
112 | $this->sessionSafeStart(); |
113 | OIDplus::cookieUtils()->setcookie(session_name(),session_id(),time()+$this->sessionLifetime); |
113 | OIDplus::cookieUtils()->setcookie(session_name(),session_id(),time()+$this->sessionLifetime); |
114 | 114 | ||
115 | if (!isset($_SESSION[$name])) return false; |
115 | if (!isset($_SESSION[$name])) return false; |
116 | } |
116 | } |
117 | 117 | ||
118 | public function delete($name) { |
118 | public function delete($name) { |
119 | if (isset($this->cacheSetValues[$name])) unset($this->cacheSetValues[$name]); |
119 | if (isset($this->cacheSetValues[$name])) unset($this->cacheSetValues[$name]); |
120 | 120 | ||
121 | if (!isset($_COOKIE[session_name()])) return; // GDPR: Only start a session when we really need one |
121 | if (!$this->isActive()) return; // GDPR: Only start a session when we really need one |
122 | $this->sessionSafeStart(); |
122 | $this->sessionSafeStart(); |
123 | OIDplus::cookieUtils()->setcookie(session_name(),session_id(),time()+$this->sessionLifetime); |
123 | OIDplus::cookieUtils()->setcookie(session_name(),session_id(),time()+$this->sessionLifetime); |
124 | 124 | ||
125 | unset($_SESSION[$name]); |
125 | unset($_SESSION[$name]); |
126 | } |
126 | } |
127 | 127 | ||
128 | public function destroySession() { |
128 | public function destroySession() { |
129 | if (!isset($_COOKIE[session_name()])) return; |
129 | if (!$this->isActive()) return; |
130 | 130 | ||
131 | $this->sessionSafeStart(); |
131 | $this->sessionSafeStart(); |
132 | OIDplus::cookieUtils()->setcookie(session_name(),session_id(),time()+$this->sessionLifetime); |
132 | OIDplus::cookieUtils()->setcookie(session_name(),session_id(),time()+$this->sessionLifetime); |
133 | 133 | ||
134 | $_SESSION = array(); |
134 | $_SESSION = array(); |
135 | session_destroy(); |
135 | session_destroy(); |
136 | session_write_close(); |
136 | session_write_close(); |
137 | OIDplus::cookieUtils()->unsetcookie(session_name()); // remove cookie, so GDPR people are happy |
137 | OIDplus::cookieUtils()->unsetcookie(session_name()); // remove cookie, so GDPR people are happy |
138 | } |
138 | } |
139 | 139 | ||
- | 140 | public function isActive() { |
|
- | 141 | return isset($_COOKIE[session_name()]); |
|
- | 142 | } |
|
- | 143 | ||
140 | protected static function encrypt($data, $key) { |
144 | protected static function encrypt($data, $key) { |
141 | if (function_exists('openssl_encrypt')) { |
145 | if (function_exists('openssl_encrypt')) { |
142 | $iv = random_bytes(16); // AES block size in CBC mode |
146 | $iv = random_bytes(16); // AES block size in CBC mode |
143 | // Encryption |
147 | // Encryption |
144 | $ciphertext = openssl_encrypt( |
148 | $ciphertext = openssl_encrypt( |