1 | <?php |
||
9 | class Session |
||
10 | { |
||
11 | /** |
||
12 | * starts the session |
||
13 | */ |
||
14 | public static function init() |
||
21 | |||
22 | /** |
||
23 | * sets a specific value to a specific key of the session |
||
24 | * |
||
25 | * @param mixed $key key |
||
26 | * @param mixed $value value |
||
27 | */ |
||
28 | public static function set($key, $value) |
||
32 | |||
33 | /** |
||
34 | * gets/returns the value of a specific key of the session |
||
35 | * |
||
36 | * @param mixed $key Usually a string, right ? |
||
37 | * @return mixed the key's value or nothing |
||
38 | */ |
||
39 | public static function get($key) |
||
48 | |||
49 | /** |
||
50 | * adds a value as a new array element to the key. |
||
51 | * useful for collecting error messages etc |
||
52 | * |
||
53 | * @param mixed $key |
||
54 | * @param mixed $value |
||
55 | */ |
||
56 | public static function add($key, $value) |
||
60 | |||
61 | /** |
||
62 | * deletes the session (= logs the user out) |
||
63 | */ |
||
64 | public static function destroy() |
||
68 | |||
69 | /** |
||
70 | * update session id in database |
||
71 | * |
||
72 | * @access public |
||
73 | * @static static method |
||
74 | * @param string $userId |
||
75 | * @param string $sessionId |
||
76 | */ |
||
77 | public static function updateSessionId($userId, $sessionId = null) |
||
85 | |||
86 | /** |
||
87 | * checks for broken session |
||
88 | * Session could be broken by Session concurrency or when user is deleted / suspended |
||
89 | * |
||
90 | * - Session concurrency is done as the following: |
||
91 | * This is done as the following: |
||
92 | * UserA logs in with his session id('123') and it will be stored in the database. |
||
93 | * Then, UserB logs in also using the same email and password of UserA from another PC, |
||
94 | * and also store the session id('456') in the database |
||
95 | * |
||
96 | * Now, Whenever UserA performs any action, |
||
97 | * You then check the session_id() against the last one stored in the database('456'), |
||
98 | * If they don't match then log both of them out. |
||
99 | * |
||
100 | * - Check for deleted / suspended users: |
||
101 | * Suspended/deleted users have no userSessionId anymore stored in database |
||
102 | * |
||
103 | * @access public |
||
104 | * @static static method |
||
105 | * @return bool |
||
106 | * @see Session::updateSessionId() |
||
107 | * @see http://stackoverflow.com/questions/6126285/php-stop-concurrent-user-logins |
||
108 | */ |
||
109 | public static function isSessionBroken() |
||
130 | |||
131 | /** |
||
132 | * Checks if the user is logged in or not |
||
133 | * |
||
134 | * @return bool user's login status |
||
135 | */ |
||
136 | public static function userIsLoggedIn() |
||
140 | } |
||
141 |