@@ -17,8 +17,9 @@ discard block |
||
17 | 17 | * @version 2.1 Beta 4 |
18 | 18 | */ |
19 | 19 | |
20 | -if (!defined('SMF')) |
|
20 | +if (!defined('SMF')) { |
|
21 | 21 | die('No direct access...'); |
22 | +} |
|
22 | 23 | |
23 | 24 | /** |
24 | 25 | * Attempt to start the session, unless it already has been. |
@@ -38,8 +39,9 @@ discard block |
||
38 | 39 | { |
39 | 40 | $parsed_url = parse_url($boardurl); |
40 | 41 | |
41 | - if (preg_match('~^\d{1,3}(\.\d{1,3}){3}$~', $parsed_url['host']) == 0 && preg_match('~(?:[^\.]+\.)?([^\.]{2,}\..+)\z~i', $parsed_url['host'], $parts) == 1) |
|
42 | - @ini_set('session.cookie_domain', '.' . $parts[1]); |
|
42 | + if (preg_match('~^\d{1,3}(\.\d{1,3}){3}$~', $parsed_url['host']) == 0 && preg_match('~(?:[^\.]+\.)?([^\.]{2,}\..+)\z~i', $parsed_url['host'], $parts) == 1) { |
|
43 | + @ini_set('session.cookie_domain', '.' . $parts[1]); |
|
44 | + } |
|
43 | 45 | } |
44 | 46 | // @todo Set the session cookie path? |
45 | 47 | |
@@ -47,8 +49,9 @@ discard block |
||
47 | 49 | if ((ini_get('session.auto_start') == 1 && !empty($modSettings['databaseSession_enable'])) || session_id() == '') |
48 | 50 | { |
49 | 51 | // Attempt to end the already-started session. |
50 | - if (ini_get('session.auto_start') == 1) |
|
51 | - session_write_close(); |
|
52 | + if (ini_get('session.auto_start') == 1) { |
|
53 | + session_write_close(); |
|
54 | + } |
|
52 | 55 | |
53 | 56 | // This is here to stop people from using bad junky PHPSESSIDs. |
54 | 57 | if (isset($_REQUEST[session_name()]) && preg_match('~^[A-Za-z0-9,-]{16,64}$~', $_REQUEST[session_name()]) == 0 && !isset($_COOKIE[session_name()])) |
@@ -63,23 +66,26 @@ discard block |
||
63 | 66 | if (!empty($modSettings['databaseSession_enable'])) |
64 | 67 | { |
65 | 68 | @ini_set('session.serialize_handler', 'php_serialize'); |
66 | - if (ini_get('session.serialize_handler') != 'php_serialize') |
|
67 | - @ini_set('session.serialize_handler', 'php'); |
|
69 | + if (ini_get('session.serialize_handler') != 'php_serialize') { |
|
70 | + @ini_set('session.serialize_handler', 'php'); |
|
71 | + } |
|
68 | 72 | session_set_save_handler('sessionOpen', 'sessionClose', 'sessionRead', 'sessionWrite', 'sessionDestroy', 'sessionGC'); |
69 | 73 | @ini_set('session.gc_probability', '1'); |
74 | + } elseif (ini_get('session.gc_maxlifetime') <= 1440 && !empty($modSettings['databaseSession_lifetime'])) { |
|
75 | + @ini_set('session.gc_maxlifetime', max($modSettings['databaseSession_lifetime'], 60)); |
|
70 | 76 | } |
71 | - elseif (ini_get('session.gc_maxlifetime') <= 1440 && !empty($modSettings['databaseSession_lifetime'])) |
|
72 | - @ini_set('session.gc_maxlifetime', max($modSettings['databaseSession_lifetime'], 60)); |
|
73 | 77 | |
74 | 78 | // Use cache setting sessions? |
75 | - if (empty($modSettings['databaseSession_enable']) && !empty($modSettings['cache_enable']) && php_sapi_name() != 'cli') |
|
76 | - call_integration_hook('integrate_session_handlers'); |
|
79 | + if (empty($modSettings['databaseSession_enable']) && !empty($modSettings['cache_enable']) && php_sapi_name() != 'cli') { |
|
80 | + call_integration_hook('integrate_session_handlers'); |
|
81 | + } |
|
77 | 82 | |
78 | 83 | session_start(); |
79 | 84 | |
80 | 85 | // Change it so the cache settings are a little looser than default. |
81 | - if (!empty($modSettings['databaseSession_loose'])) |
|
82 | - header('Cache-Control: private'); |
|
86 | + if (!empty($modSettings['databaseSession_loose'])) { |
|
87 | + header('Cache-Control: private'); |
|
88 | + } |
|
83 | 89 | } |
84 | 90 | |
85 | 91 | // Set the randomly generated code. |
@@ -125,8 +131,9 @@ discard block |
||
125 | 131 | { |
126 | 132 | global $smcFunc; |
127 | 133 | |
128 | - if (preg_match('~^[A-Za-z0-9,-]{16,64}$~', $session_id) == 0) |
|
129 | - return ''; |
|
134 | + if (preg_match('~^[A-Za-z0-9,-]{16,64}$~', $session_id) == 0) { |
|
135 | + return ''; |
|
136 | + } |
|
130 | 137 | |
131 | 138 | // Look for it in the database. |
132 | 139 | $result = $smcFunc['db_query']('', ' |
@@ -155,8 +162,9 @@ discard block |
||
155 | 162 | { |
156 | 163 | global $smcFunc; |
157 | 164 | |
158 | - if (preg_match('~^[A-Za-z0-9,-]{16,64}$~', $session_id) == 0) |
|
159 | - return false; |
|
165 | + if (preg_match('~^[A-Za-z0-9,-]{16,64}$~', $session_id) == 0) { |
|
166 | + return false; |
|
167 | + } |
|
160 | 168 | |
161 | 169 | // First try to update an existing row... |
162 | 170 | $smcFunc['db_query']('', ' |
@@ -171,13 +179,14 @@ discard block |
||
171 | 179 | ); |
172 | 180 | |
173 | 181 | // If that didn't work, try inserting a new one. |
174 | - if ($smcFunc['db_affected_rows']() == 0) |
|
175 | - $smcFunc['db_insert']('ignore', |
|
182 | + if ($smcFunc['db_affected_rows']() == 0) { |
|
183 | + $smcFunc['db_insert']('ignore', |
|
176 | 184 | '{db_prefix}sessions', |
177 | 185 | array('session_id' => 'string', 'data' => 'string', 'last_update' => 'int'), |
178 | 186 | array($session_id, $data, time()), |
179 | 187 | array('session_id') |
180 | 188 | ); |
189 | + } |
|
181 | 190 | |
182 | 191 | return ($smcFunc['db_affected_rows']() == 0 ? false : true); |
183 | 192 | } |
@@ -192,8 +201,9 @@ discard block |
||
192 | 201 | { |
193 | 202 | global $smcFunc; |
194 | 203 | |
195 | - if (preg_match('~^[A-Za-z0-9,-]{16,64}$~', $session_id) == 0) |
|
196 | - return false; |
|
204 | + if (preg_match('~^[A-Za-z0-9,-]{16,64}$~', $session_id) == 0) { |
|
205 | + return false; |
|
206 | + } |
|
197 | 207 | |
198 | 208 | // Just delete the row... |
199 | 209 | $smcFunc['db_query']('', ' |
@@ -219,8 +229,9 @@ discard block |
||
219 | 229 | global $modSettings, $smcFunc; |
220 | 230 | |
221 | 231 | // Just set to the default or lower? Ignore it for a higher value. (hopefully) |
222 | - if (!empty($modSettings['databaseSession_lifetime']) && ($max_lifetime <= 1440 || $modSettings['databaseSession_lifetime'] > $max_lifetime)) |
|
223 | - $max_lifetime = max($modSettings['databaseSession_lifetime'], 60); |
|
232 | + if (!empty($modSettings['databaseSession_lifetime']) && ($max_lifetime <= 1440 || $modSettings['databaseSession_lifetime'] > $max_lifetime)) { |
|
233 | + $max_lifetime = max($modSettings['databaseSession_lifetime'], 60); |
|
234 | + } |
|
224 | 235 | |
225 | 236 | // Clean up after yerself ;). |
226 | 237 | $smcFunc['db_query']('', ' |