source: trunk/forum/common.php

Last change on this file was 702, checked in by george, 15 years ago
  • Upraveno: Aktualizace fóra.
File size: 6.2 KB
Line 
1<?php
2/**
3*
4* @package phpBB3
5* @version $Id$
6* @copyright (c) 2005 phpBB Group
7* @license http://opensource.org/licenses/gpl-license.php GNU Public License
8*
9* Minimum Requirement: PHP 4.3.3
10*/
11
12/**
13*/
14if (!defined('IN_PHPBB'))
15{
16 exit;
17}
18
19$starttime = explode(' ', microtime());
20$starttime = $starttime[1] + $starttime[0];
21
22// Report all errors, except notices and deprecation messages
23if (!defined('E_DEPRECATED'))
24{
25 define('E_DEPRECATED', 8192);
26}
27error_reporting(E_ALL ^ E_NOTICE ^ E_DEPRECATED);
28
29/*
30* Remove variables created by register_globals from the global scope
31* Thanks to Matt Kavanagh
32*/
33function deregister_globals()
34{
35 $not_unset = array(
36 'GLOBALS' => true,
37 '_GET' => true,
38 '_POST' => true,
39 '_COOKIE' => true,
40 '_REQUEST' => true,
41 '_SERVER' => true,
42 '_SESSION' => true,
43 '_ENV' => true,
44 '_FILES' => true,
45 'phpEx' => true,
46 'phpbb_root_path' => true
47 );
48
49 // Not only will array_merge and array_keys give a warning if
50 // a parameter is not an array, array_merge will actually fail.
51 // So we check if _SESSION has been initialised.
52 if (!isset($_SESSION) || !is_array($_SESSION))
53 {
54 $_SESSION = array();
55 }
56
57 // Merge all into one extremely huge array; unset this later
58 $input = array_merge(
59 array_keys($_GET),
60 array_keys($_POST),
61 array_keys($_COOKIE),
62 array_keys($_SERVER),
63 array_keys($_SESSION),
64 array_keys($_ENV),
65 array_keys($_FILES)
66 );
67
68 foreach ($input as $varname)
69 {
70 if (isset($not_unset[$varname]))
71 {
72 // Hacking attempt. No point in continuing unless it's a COOKIE
73 if ($varname !== 'GLOBALS' || isset($_GET['GLOBALS']) || isset($_POST['GLOBALS']) || isset($_SERVER['GLOBALS']) || isset($_SESSION['GLOBALS']) || isset($_ENV['GLOBALS']) || isset($_FILES['GLOBALS']))
74 {
75 exit;
76 }
77 else
78 {
79 $cookie = &$_COOKIE;
80 while (isset($cookie['GLOBALS']))
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// If we are on PHP >= 6.0.0 we do not need some code
101if (version_compare(PHP_VERSION, '6.0.0-dev', '>='))
102{
103 /**
104 * @ignore
105 */
106 define('STRIP', false);
107}
108else
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
121if (defined('IN_CRON'))
122{
123 $phpbb_root_path = dirname(__FILE__) . DIRECTORY_SEPARATOR;
124}
125
126if (!file_exists($phpbb_root_path . 'config.' . $phpEx))
127{
128 die("<p>The config.$phpEx file could not be found.</p><p><a href=\"{$phpbb_root_path}install/index.$phpEx\">Click here to install phpBB</a></p>");
129}
130
131require($phpbb_root_path . 'config.' . $phpEx);
132
133if (!defined('PHPBB_INSTALLED'))
134{
135 // Redirect the user to the installer
136 // We have to generate a full HTTP/1.1 header here since we can't guarantee to have any of the information
137 // available as used by the redirect function
138 $server_name = (!empty($_SERVER['HTTP_HOST'])) ? strtolower($_SERVER['HTTP_HOST']) : ((!empty($_SERVER['SERVER_NAME'])) ? $_SERVER['SERVER_NAME'] : getenv('SERVER_NAME'));
139 $server_port = (!empty($_SERVER['SERVER_PORT'])) ? (int) $_SERVER['SERVER_PORT'] : (int) getenv('SERVER_PORT');
140 $secure = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 1 : 0;
141
142 $script_name = (!empty($_SERVER['PHP_SELF'])) ? $_SERVER['PHP_SELF'] : getenv('PHP_SELF');
143 if (!$script_name)
144 {
145 $script_name = (!empty($_SERVER['REQUEST_URI'])) ? $_SERVER['REQUEST_URI'] : getenv('REQUEST_URI');
146 }
147
148 // Replace any number of consecutive backslashes and/or slashes with a single slash
149 // (could happen on some proxy setups and/or Windows servers)
150 $script_path = trim(dirname($script_name)) . '/install/index.' . $phpEx;
151 $script_path = preg_replace('#[\\\\/]{2,}#', '/', $script_path);
152
153 $url = (($secure) ? 'https://' : 'http://') . $server_name;
154
155 if ($server_port && (($secure && $server_port <> 443) || (!$secure && $server_port <> 80)))
156 {
157 // HTTP HOST can carry a port number...
158 if (strpos($server_name, ':') === false)
159 {
160 $url .= ':' . $server_port;
161 }
162 }
163
164 $url .= $script_path;
165 header('Location: ' . $url);
166 exit;
167}
168
169if (defined('DEBUG_EXTRA'))
170{
171 $base_memory_usage = 0;
172 if (function_exists('memory_get_usage'))
173 {
174 $base_memory_usage = memory_get_usage();
175 }
176}
177
178// Load Extensions
179// dl() is deprecated and disabled by default as of PHP 5.3.
180if (!empty($load_extensions) && function_exists('dl'))
181{
182 $load_extensions = explode(',', $load_extensions);
183
184 foreach ($load_extensions as $extension)
185 {
186 @dl(trim($extension));
187 }
188}
189
190// Include files
191require($phpbb_root_path . 'includes/acm/acm_' . $acm_type . '.' . $phpEx);
192require($phpbb_root_path . 'includes/cache.' . $phpEx);
193require($phpbb_root_path . 'includes/template.' . $phpEx);
194require($phpbb_root_path . 'includes/session.' . $phpEx);
195require($phpbb_root_path . 'includes/auth.' . $phpEx);
196
197require($phpbb_root_path . 'includes/functions.' . $phpEx);
198require($phpbb_root_path . 'includes/functions_content.' . $phpEx);
199
200require($phpbb_root_path . 'includes/constants.' . $phpEx);
201require($phpbb_root_path . 'includes/db/' . $dbms . '.' . $phpEx);
202require($phpbb_root_path . 'includes/utf/utf_tools.' . $phpEx);
203
204// Set PHP error handler to ours
205set_error_handler(defined('PHPBB_MSG_HANDLER') ? PHPBB_MSG_HANDLER : 'msg_handler');
206
207// Instantiate some basic classes
208$user = new user();
209$auth = new auth();
210$template = new template();
211$cache = new cache();
212$db = new $sql_db();
213
214// Connect to DB
215$db->sql_connect($dbhost, $dbuser, $dbpasswd, $dbname, $dbport, false, defined('PHPBB_DB_NEW_LINK') ? PHPBB_DB_NEW_LINK : false);
216
217// We do not need this any longer, unset for safety purposes
218unset($dbpasswd);
219
220// Grab global variables, re-cache if necessary
221$config = $cache->obtain_config();
222
223// Add own hook handler
224require($phpbb_root_path . 'includes/hooks/index.' . $phpEx);
225$phpbb_hook = new phpbb_hook(array('exit_handler', 'phpbb_user_session_handler', 'append_sid', array('template', 'display')));
226
227foreach ($cache->obtain_hooks() as $hook)
228{
229 @include($phpbb_root_path . 'includes/hooks/' . $hook . '.' . $phpEx);
230}
231
232?>
Note: See TracBrowser for help on using the repository browser.