2 /***************************************************************************
5 * begin : Saturday, Feb 23, 2001
6 * copyright : (C) 2001 The phpBB Group
7 * email : support@phpbb.com
9 * $Id: common.php,v 1.74.2.14 2004/11/18 17:49:34 acydburn Exp $
11 ***************************************************************************/
13 /***************************************************************************
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or
18 * (at your option) any later version.
20 ***************************************************************************/
22 if ( !defined('IN_PHPBB') )
24 die("Hacking attempt");
28 error_reporting (E_ERROR | E_WARNING | E_PARSE); // This will NOT report uninitialized variables
29 set_magic_quotes_runtime(0); // Disable magic_quotes_runtime
31 // The following code (unsetting globals) was contributed by Matt Kavanagh
33 // PHP5 with register_long_arrays off?
34 if (!isset($HTTP_POST_VARS) && isset($_POST))
36 $HTTP_POST_VARS = $_POST;
37 $HTTP_GET_VARS = $_GET;
38 $HTTP_SERVER_VARS = $_SERVER;
39 $HTTP_COOKIE_VARS = $_COOKIE;
40 $HTTP_ENV_VARS = $_ENV;
41 $HTTP_POST_FILES = $_FILES;
43 // _SESSION is the only superglobal which is conditionally set
46 $HTTP_SESSION_VARS = $_SESSION;
50 if (@phpversion() < '4.0.0')
52 // PHP3 path; in PHP3, globals are _always_ registered
54 // We 'flip' the array of variables to test like this so that
55 // we can validate later with isset($test[$var]) (no in_array())
56 $test = array('HTTP_GET_VARS' => NULL, 'HTTP_POST_VARS' => NULL, 'HTTP_COOKIE_VARS' => NULL, 'HTTP_SERVER_VARS' => NULL, 'HTTP_ENV_VARS' => NULL, 'HTTP_POST_FILES' => NULL);
58 // Loop through each input array
60 while (list($input,) = @each($test))
62 while (list($var,) = @each($$input))
64 // Validate the variable to be unset
65 if (!isset($test[$var]) && $var != 'test' && $var != 'input')
72 else if (@ini_get('register_globals') == '1' || strtolower(@ini_get('register_globals')) == 'on')
76 // Not only will array_merge give a warning if a parameter
77 // is not an array, it will actually fail. So we check if
78 // HTTP_SESSION_VARS has been initialised.
79 if (!isset($HTTP_SESSION_VARS))
81 $HTTP_SESSION_VARS = array();
84 // Merge all into one extremely huge array; unset
86 $input = array_merge($HTTP_GET_VARS, $HTTP_POST_VARS, $HTTP_COOKIE_VARS, $HTTP_SERVER_VARS, $HTTP_SESSION_VARS, $HTTP_ENV_VARS, $HTTP_POST_FILES);
88 unset($input['input']);
90 while (list($var,) = @each($input))
99 // addslashes to vars if magic_quotes_gpc is off
100 // this is a security precaution to prevent someone
101 // trying to break out of a SQL statement.
103 if( !get_magic_quotes_gpc() )
105 if( is_array($HTTP_GET_VARS) )
107 while( list($k, $v) = each($HTTP_GET_VARS) )
109 if( is_array($HTTP_GET_VARS[$k]) )
111 while( list($k2, $v2) = each($HTTP_GET_VARS[$k]) )
113 $HTTP_GET_VARS[$k][$k2] = addslashes($v2);
115 @reset($HTTP_GET_VARS[$k]);
119 $HTTP_GET_VARS[$k] = addslashes($v);
122 @reset($HTTP_GET_VARS);
125 if( is_array($HTTP_POST_VARS) )
127 while( list($k, $v) = each($HTTP_POST_VARS) )
129 if( is_array($HTTP_POST_VARS[$k]) )
131 while( list($k2, $v2) = each($HTTP_POST_VARS[$k]) )
133 $HTTP_POST_VARS[$k][$k2] = addslashes($v2);
135 @reset($HTTP_POST_VARS[$k]);
139 $HTTP_POST_VARS[$k] = addslashes($v);
142 @reset($HTTP_POST_VARS);
145 if( is_array($HTTP_COOKIE_VARS) )
147 while( list($k, $v) = each($HTTP_COOKIE_VARS) )
149 if( is_array($HTTP_COOKIE_VARS[$k]) )
151 while( list($k2, $v2) = each($HTTP_COOKIE_VARS[$k]) )
153 $HTTP_COOKIE_VARS[$k][$k2] = addslashes($v2);
155 @reset($HTTP_COOKIE_VARS[$k]);
159 $HTTP_COOKIE_VARS[$k] = addslashes($v);
162 @reset($HTTP_COOKIE_VARS);
167 // Define some basic configuration arrays this also prevents
168 // malicious rewriting of language and otherarray values via
171 $board_config = array();
176 $nav_links = array();
177 $gen_simple_header = FALSE;
179 include($phpbb_root_path . 'config.'.$phpEx);
181 if( !defined("PHPBB_INSTALLED") )
183 header("Location: install/install.$phpEx");
187 include($phpbb_root_path . 'includes/constants.'.$phpEx);
188 include($phpbb_root_path . 'includes/template.'.$phpEx);
189 include($phpbb_root_path . 'includes/sessions.'.$phpEx);
190 include($phpbb_root_path . 'includes/auth.'.$phpEx);
191 include($phpbb_root_path . 'includes/functions.'.$phpEx);
192 include($phpbb_root_path . 'includes/db.'.$phpEx);
195 // Obtain and encode users IP
197 // I'm removing HTTP_X_FORWARDED_FOR ... this may well cause other problems such as
198 // private range IP's appearing instead of the guilty routable IP, tough, don't
199 // even bother complaining ... go scream and shout at the idiots out there who feel
200 // "clever" is doing harm rather than good ... karma is a great thing ... :)
202 $client_ip = ( !empty($HTTP_SERVER_VARS['REMOTE_ADDR']) ) ? $HTTP_SERVER_VARS['REMOTE_ADDR'] : ( ( !empty($HTTP_ENV_VARS['REMOTE_ADDR']) ) ? $HTTP_ENV_VARS['REMOTE_ADDR'] : $REMOTE_ADDR );
203 $user_ip = encode_ip($client_ip);
206 // Setup forum wide options, if this fails
207 // then we output a CRITICAL_ERROR since
208 // basic forum information is not available
211 FROM " . CONFIG_TABLE;
212 if( !($result = $db->sql_query($sql)) )
214 message_die(CRITICAL_ERROR, "Could not query config information", "", __LINE__, __FILE__, $sql);
217 while ( $row = $db->sql_fetchrow($result) )
219 $board_config[$row['config_name']] = $row['config_value'];
222 if (file_exists('install') || file_exists('contrib'))
224 message_die(GENERAL_MESSAGE, 'Please ensure both the install/ and contrib/ directories are deleted');
228 // Show 'Board is disabled' message if needed.
230 if( $board_config['board_disable'] && !defined("IN_ADMIN") && !defined("IN_LOGIN") )
232 message_die(GENERAL_MESSAGE, 'Board_disable', 'Information');