Conditions | 20 |
Paths | 390 |
Total Lines | 69 |
Code Lines | 36 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
26 | function loadSession() |
||
27 | { |
||
28 | global $modSettings, $boardurl, $sc, $smcFunc, $cache_enable; |
||
29 | |||
30 | // Attempt to change a few PHP settings. |
||
31 | @ini_set('session.use_cookies', true); |
||
|
|||
32 | @ini_set('session.use_only_cookies', false); |
||
33 | @ini_set('url_rewriter.tags', ''); |
||
34 | @ini_set('session.use_trans_sid', false); |
||
35 | @ini_set('arg_separator.output', '&'); |
||
36 | |||
37 | // Allows mods to change/add PHP settings |
||
38 | call_integration_hook('integrate_load_session'); |
||
39 | |||
40 | if (!empty($modSettings['globalCookies'])) |
||
41 | { |
||
42 | $parsed_url = parse_iri($boardurl); |
||
43 | |||
44 | if (preg_match('~^\d{1,3}(\.\d{1,3}){3}$~', $parsed_url['host']) == 0 && preg_match('~(?:[^\.]+\.)?([^\.]{2,}\..+)\z~i', $parsed_url['host'], $parts) == 1) |
||
45 | @ini_set('session.cookie_domain', '.' . $parts[1]); |
||
46 | } |
||
47 | // @todo Set the session cookie path? |
||
48 | |||
49 | // If it's already been started... probably best to skip this. |
||
50 | if ((ini_get('session.auto_start') == 1 && !empty($modSettings['databaseSession_enable'])) || session_id() == '') |
||
51 | { |
||
52 | // Attempt to end the already-started session. |
||
53 | if (ini_get('session.auto_start') == 1) |
||
54 | session_write_close(); |
||
55 | |||
56 | // This is here to stop people from using bad junky PHPSESSIDs. |
||
57 | if (isset($_REQUEST[session_name()]) && preg_match('~^[A-Za-z0-9,-]{16,64}$~', $_REQUEST[session_name()]) == 0 && !isset($_COOKIE[session_name()])) |
||
58 | { |
||
59 | $session_id = md5(md5('smf_sess_' . time()) . $smcFunc['random_int']()); |
||
60 | $_REQUEST[session_name()] = $session_id; |
||
61 | $_GET[session_name()] = $session_id; |
||
62 | $_POST[session_name()] = $session_id; |
||
63 | } |
||
64 | |||
65 | // Use database sessions? (they don't work in 4.1.x!) |
||
66 | if (!empty($modSettings['databaseSession_enable'])) |
||
67 | { |
||
68 | @ini_set('session.serialize_handler', 'php_serialize'); |
||
69 | if (ini_get('session.serialize_handler') != 'php_serialize') |
||
70 | @ini_set('session.serialize_handler', 'php'); |
||
71 | session_set_save_handler('sessionOpen', 'sessionClose', 'sessionRead', 'sessionWrite', 'sessionDestroy', 'sessionGC'); |
||
72 | @ini_set('session.gc_probability', '1'); |
||
73 | } |
||
74 | elseif (ini_get('session.gc_maxlifetime') <= 1440 && !empty($modSettings['databaseSession_lifetime'])) |
||
75 | @ini_set('session.gc_maxlifetime', max($modSettings['databaseSession_lifetime'], 60)); |
||
76 | |||
77 | // Use cache setting sessions? |
||
78 | if (empty($modSettings['databaseSession_enable']) && !empty($cache_enable) && php_sapi_name() != 'cli') |
||
79 | call_integration_hook('integrate_session_handlers'); |
||
80 | |||
81 | session_start(); |
||
82 | |||
83 | // Change it so the cache settings are a little looser than default. |
||
84 | if (!empty($modSettings['databaseSession_loose'])) |
||
85 | header('cache-control: private'); |
||
86 | } |
||
87 | |||
88 | // Set the randomly generated code. |
||
89 | if (!isset($_SESSION['session_var'])) |
||
90 | { |
||
91 | $_SESSION['session_value'] = md5(session_id() . $smcFunc['random_int']()); |
||
92 | $_SESSION['session_var'] = substr(preg_replace('~^\d+~', '', sha1($smcFunc['random_int']() . session_id() . $smcFunc['random_int']())), 0, $smcFunc['random_int'](7, 12)); |
||
93 | } |
||
94 | $sc = $_SESSION['session_value']; |
||
95 | } |
||
245 | ?> |