1 | <?php |
||
5 | final class SessionManager |
||
6 | { |
||
7 | /** |
||
8 | * As this is a singleton, construction and clone are disabled |
||
9 | * use SessionManager::getInstance() if you need the instance |
||
10 | */ |
||
11 | private function __construct(){} |
||
12 | |||
13 | private function __clone(){} |
||
14 | |||
15 | /** |
||
16 | * @return SessionManager|null |
||
17 | */ |
||
18 | public static function getInstance() |
||
26 | |||
27 | /** |
||
28 | * Creates a secure session |
||
29 | * @param $name |
||
30 | * @param int $lifetime |
||
31 | * @param string $path |
||
32 | * @param null $domain |
||
33 | * @param null $secure |
||
34 | */ |
||
35 | public static function sessionStart($name, $lifetime = 0, $path = '/', $domain = null, $secure = null) |
||
74 | |||
75 | private function shouldRandomlyRegenerate() |
||
79 | |||
80 | |||
81 | /** |
||
82 | * Checks session IP and user agent are still the same |
||
83 | * @return bool |
||
84 | */ |
||
85 | private static function preventHijacking() |
||
98 | |||
99 | /** |
||
100 | * Creates a fresh session Id to make it harder to hack |
||
101 | * If the site is very slow in parts increase the expiry time |
||
102 | * 10 seconds is a good default which allows ajax calls to work |
||
103 | * without losing the session |
||
104 | */ |
||
105 | private static function regenerateSession() |
||
131 | |||
132 | /** |
||
133 | * Checks whether the session has expired or not |
||
134 | * @return bool |
||
135 | */ |
||
136 | private static function validateSession() |
||
148 | |||
149 | /** |
||
150 | * Resets the session |
||
151 | */ |
||
152 | public static function destroySession() |
||
161 | |||
162 | /** |
||
163 | * @param $key |
||
164 | * @param $val |
||
165 | */ |
||
166 | public static function set($key, $val) |
||
170 | |||
171 | /** |
||
172 | * @param $key |
||
173 | * @return null |
||
174 | */ |
||
175 | public static function get($key) |
||
179 | |||
180 | /** |
||
181 | * @param $key |
||
182 | * @param $val |
||
183 | */ |
||
184 | public static function destroy($key) |
||
188 | } |