|
1 <?php |
|
2 /** |
|
3 * |
|
4 * @package phpBB3 |
|
5 * @copyright (c) 2011 phpBB Group |
|
6 * @license http://opensource.org/licenses/gpl-license.php GNU Public License |
|
7 * |
|
8 */ |
|
9 |
|
10 /** |
|
11 */ |
|
12 if (!defined('IN_PHPBB')) |
|
13 { |
|
14 exit; |
|
15 } |
|
16 |
|
17 // Report all errors, except notices and deprecation messages |
|
18 if (!defined('E_DEPRECATED')) |
|
19 { |
|
20 define('E_DEPRECATED', 8192); |
|
21 } |
|
22 error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED); |
|
23 |
|
24 /* |
|
25 * Remove variables created by register_globals from the global scope |
|
26 * Thanks to Matt Kavanagh |
|
27 */ |
|
28 function deregister_globals() |
|
29 { |
|
30 $not_unset = array( |
|
31 'GLOBALS' => true, |
|
32 '_GET' => true, |
|
33 '_POST' => true, |
|
34 '_COOKIE' => true, |
|
35 '_REQUEST' => true, |
|
36 '_SERVER' => true, |
|
37 '_SESSION' => true, |
|
38 '_ENV' => true, |
|
39 '_FILES' => true, |
|
40 'phpEx' => true, |
|
41 'phpbb_root_path' => true |
|
42 ); |
|
43 |
|
44 // Not only will array_merge and array_keys give a warning if |
|
45 // a parameter is not an array, array_merge will actually fail. |
|
46 // So we check if _SESSION has been initialised. |
|
47 if (!isset($_SESSION) || !is_array($_SESSION)) |
|
48 { |
|
49 $_SESSION = array(); |
|
50 } |
|
51 |
|
52 // Merge all into one extremely huge array; unset this later |
|
53 $input = array_merge( |
|
54 array_keys($_GET), |
|
55 array_keys($_POST), |
|
56 array_keys($_COOKIE), |
|
57 array_keys($_SERVER), |
|
58 array_keys($_SESSION), |
|
59 array_keys($_ENV), |
|
60 array_keys($_FILES) |
|
61 ); |
|
62 |
|
63 foreach ($input as $varname) |
|
64 { |
|
65 if (isset($not_unset[$varname])) |
|
66 { |
|
67 // Hacking attempt. No point in continuing unless it's a COOKIE (so a cookie called GLOBALS doesn't lock users out completely) |
|
68 if ($varname !== 'GLOBALS' || isset($_GET['GLOBALS']) || isset($_POST['GLOBALS']) || isset($_SERVER['GLOBALS']) || isset($_SESSION['GLOBALS']) || isset($_ENV['GLOBALS']) || isset($_FILES['GLOBALS'])) |
|
69 { |
|
70 exit; |
|
71 } |
|
72 else |
|
73 { |
|
74 $cookie = &$_COOKIE; |
|
75 while (isset($cookie['GLOBALS'])) |
|
76 { |
|
77 if (!is_array($cookie['GLOBALS'])) |
|
78 { |
|
79 break; |
|
80 } |
|
81 |
|
82 foreach ($cookie['GLOBALS'] as $registered_var => $value) |
|
83 { |
|
84 if (!isset($not_unset[$registered_var])) |
|
85 { |
|
86 unset($GLOBALS[$registered_var]); |
|
87 } |
|
88 } |
|
89 $cookie = &$cookie['GLOBALS']; |
|
90 } |
|
91 } |
|
92 } |
|
93 |
|
94 unset($GLOBALS[$varname]); |
|
95 } |
|
96 |
|
97 unset($input); |
|
98 } |
|
99 |
|
100 // Register globals and magic quotes have been dropped in PHP 5.4 |
|
101 if (version_compare(PHP_VERSION, '5.4.0-dev', '>=')) |
|
102 { |
|
103 /** |
|
104 * @ignore |
|
105 */ |
|
106 define('STRIP', false); |
|
107 } |
|
108 else |
|
109 { |
|
110 @set_magic_quotes_runtime(0); |
|
111 |
|
112 // Be paranoid with passed vars |
|
113 if (@ini_get('register_globals') == '1' || strtolower(@ini_get('register_globals')) == 'on' || !function_exists('ini_get')) |
|
114 { |
|
115 deregister_globals(); |
|
116 } |
|
117 |
|
118 define('STRIP', (get_magic_quotes_gpc()) ? true : false); |
|
119 } |
|
120 |
|
121 // Prevent date/time functions from throwing E_WARNING on PHP 5.3 by setting a default timezone |
|
122 if (function_exists('date_default_timezone_set') && function_exists('date_default_timezone_get')) |
|
123 { |
|
124 // For PHP 5.1.0 the date/time functions have been rewritten |
|
125 // and setting a timezone is required prior to calling any date/time function. |
|
126 |
|
127 // Since PHP 5.2.0 calls to date/time functions without having a timezone set |
|
128 // result in E_STRICT errors being thrown. |
|
129 // Note: We already exclude E_STRICT errors |
|
130 // (to be exact: they are not included in E_ALL in PHP 5.2) |
|
131 |
|
132 // In PHP 5.3.0 the error level has been raised to E_WARNING which causes problems |
|
133 // because we show E_WARNING errors and do not set a default timezone. |
|
134 // This is because we have our own timezone handling and work in UTC only anyway. |
|
135 |
|
136 // So what we basically want to do is set our timezone to UTC, |
|
137 // but we don't know what other scripts (such as bridges) are involved, |
|
138 // so we check whether a timezone is already set by calling date_default_timezone_get(). |
|
139 |
|
140 // Unfortunately, date_default_timezone_get() itself might throw E_WARNING |
|
141 // if no timezone has been set, so we have to keep it quiet with @. |
|
142 |
|
143 // date_default_timezone_get() tries to guess the correct timezone first |
|
144 // and then falls back to UTC when everything fails. |
|
145 // We just set the timezone to whatever date_default_timezone_get() returns. |
|
146 date_default_timezone_set(@date_default_timezone_get()); |
|
147 } |
|
148 |
|
149 $starttime = explode(' ', microtime()); |
|
150 $starttime = $starttime[1] + $starttime[0]; |