Rev 563 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 563 | Rev 566 | ||
---|---|---|---|
Line 21... | Line 21... | ||
21 | 21 | ||
22 | class OIDplusSessionHandler { |
22 | class OIDplusSessionHandler { |
23 | 23 | ||
24 | private $secret = ''; |
24 | private $secret = ''; |
25 | protected $sessionLifetime = ''; |
25 | protected $sessionLifetime = ''; |
26 | public $simulate = false; |
- | |
27 | 26 | ||
28 | public function __construct() { |
27 | public function __construct() { |
29 | $this->sessionLifetime = OIDplus::baseConfig()->getValue('SESSION_LIFETIME', 30*60); |
28 | $this->sessionLifetime = OIDplus::baseConfig()->getValue('SESSION_LIFETIME', 30*60); |
30 | $this->secret = OIDplus::baseConfig()->getValue('SERVER_SECRET'); |
29 | $this->secret = OIDplus::baseConfig()->getValue('SERVER_SECRET'); |
31 | 30 | ||
Line 86... | Line 85... | ||
86 | 85 | ||
87 | private $cacheSetValues = array(); // Important if you do a setValue() followed by an getValue() |
86 | private $cacheSetValues = array(); // Important if you do a setValue() followed by an getValue() |
88 | 87 | ||
89 | public function setValue($name, $value) { |
88 | public function setValue($name, $value) { |
90 | $this->cacheSetValues[$name] = self::encrypt($value, $this->secret); |
89 | $this->cacheSetValues[$name] = self::encrypt($value, $this->secret); |
91 | if ($this->simulate) return; |
- | |
92 | 90 | ||
93 | $this->sessionSafeStart(); |
91 | $this->sessionSafeStart(); |
94 | OIDplus::cookieUtils()->setcookie(session_name(),session_id(),time()+$this->sessionLifetime); |
92 | OIDplus::cookieUtils()->setcookie(session_name(),session_id(),time()+$this->sessionLifetime); |
95 | 93 | ||
96 | $_SESSION[$name] = self::encrypt($value, $this->secret); |
94 | $_SESSION[$name] = self::encrypt($value, $this->secret); |
97 | } |
95 | } |
98 | 96 | ||
99 | public function getValue($name) { |
97 | public function getValue($name) { |
100 | 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); |
101 | if ($this->simulate) return null; |
- | |
102 | 99 | ||
103 | if (!isset($_COOKIE[session_name()])) return null; // GDPR: Only start a session when we really need one |
100 | if (!isset($_COOKIE[session_name()])) return null; // GDPR: Only start a session when we really need one |
104 | $this->sessionSafeStart(); |
101 | $this->sessionSafeStart(); |
105 | OIDplus::cookieUtils()->setcookie(session_name(),session_id(),time()+$this->sessionLifetime); |
102 | OIDplus::cookieUtils()->setcookie(session_name(),session_id(),time()+$this->sessionLifetime); |
106 | 103 |