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 session concurrency |
||
88 | * |
||
89 | * This is done as the following: |
||
90 | * UserA logs in with his session id('123') and it will be stored in the database. |
||
91 | * Then, UserB logs in also using the same email and password of UserA from another PC, |
||
92 | * and also store the session id('456') in the database |
||
93 | * |
||
94 | * Now, Whenever UserA performs any action, |
||
95 | * You then check the session_id() against the last one stored in the database('456'), |
||
96 | * If they don't match then log both of them out. |
||
97 | * |
||
98 | * @access public |
||
99 | * @static static method |
||
100 | * @return bool |
||
101 | * @see Session::updateSessionId() |
||
102 | * @see http://stackoverflow.com/questions/6126285/php-stop-concurrent-user-logins |
||
103 | */ |
||
104 | public static function isConcurrentSessionExists() |
||
125 | |||
126 | /** |
||
127 | * Checks if the user is logged in or not |
||
128 | * |
||
129 | * @return bool user's login status |
||
130 | */ |
||
131 | public static function userIsLoggedIn() |
||
135 | } |
||
136 |