1. <?php
  2. /**
  3. *
  4. * @package phpBB3
  5. * @version $Id: common.php 8479 2008-03-29 00:22:48Z naderman $
  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. if (!defined('IN_PHPBB'))
  14. {
  15. exit;
  16. }
  17. $starttime = explode(' ', microtime());
  18. $starttime = $starttime[1] + $starttime[0];
  19. // Report all errors, except notices
  20. error_reporting(E_ALL ^ E_NOTICE);
  21. /*
  22. * Remove variables created by register_globals from the global scope
  23. * Thanks to Matt Kavanagh
  24. */
  25. function deregister_globals()
  26. {
  27. $not_unset = array(
  28. 'GLOBALS' => true,
  29. '_GET' => true,
  30. '_POST' => true,
  31. '_COOKIE' => true,
  32. '_REQUEST' => true,
  33. '_SERVER' => true,
  34. '_SESSION' => true,
  35. '_ENV' => true,
  36. '_FILES' => true,
  37. 'phpEx' => true,
  38. 'phpbb_root_path' => true
  39. );
  40. // Not only will array_merge and array_keys give a warning if
  41. // a parameter is not an array, array_merge will actually fail.
  42. // So we check if _SESSION has been initialised.
  43. if (!isset($_SESSION) || !is_array($_SESSION))
  44. {
  45. $_SESSION = array();
  46. }
  47. // Merge all into one extremely huge array; unset this later
  48. $input = array_merge(
  49. array_keys($_GET),
  50. array_keys($_POST),
  51. array_keys($_COOKIE),
  52. array_keys($_SERVER),
  53. array_keys($_SESSION),
  54. array_keys($_ENV),
  55. array_keys($_FILES)
  56. );
  57. foreach ($input as $varname)
  58. {
  59. if (isset($not_unset[$varname]))
  60. {
  61. // Hacking attempt. No point in continuing unless it's a COOKIE
  62. if ($varname !== 'GLOBALS' || isset($_GET['GLOBALS']) || isset($_POST['GLOBALS']) || isset($_SERVER['GLOBALS']) || isset($_SESSION['GLOBALS']) || isset($_ENV['GLOBALS']) || isset($_FILES['GLOBALS']))
  63. {
  64. exit;
  65. }
  66. else
  67. {
  68. $cookie = &$_COOKIE;
  69. while (isset($cookie['GLOBALS']))
  70. {
  71. foreach ($cookie['GLOBALS'] as $registered_var => $value)
  72. {
  73. if (!isset($not_unset[$registered_var]))
  74. {
  75. unset($GLOBALS[$registered_var]);
  76. }
  77. }
  78. $cookie = &$cookie['GLOBALS'];
  79. }
  80. }
  81. }
  82. unset($GLOBALS[$varname]);
  83. }
  84. unset($input);
  85. }
  86. // If we are on PHP >= 6.0.0 we do not need some code
  87. if (version_compare(PHP_VERSION, '6.0.0-dev', '>='))
  88. {
  89. /**
  90. * @ignore
  91. */
  92. define('STRIP', false);
  93. }
  94. else
  95. {
  96. set_magic_quotes_runtime(0);
  97. // Be paranoid with passed vars
  98. if (@ini_get('register_globals') == '1' || strtolower(@ini_get('register_globals')) == 'on' || !function_exists('ini_get'))
  99. {
  100. deregister_globals();
  101. }
  102. define('STRIP', (get_magic_quotes_gpc()) ? true : false);
  103. }
  104. if (defined('IN_CRON'))
  105. {
  106. $phpbb_root_path = dirname(__FILE__) . DIRECTORY_SEPARATOR;
  107. }
  108. if (!file_exists($phpbb_root_path . 'config.' . $phpEx))
  109. {
  110. 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>");
  111. }
  112. require($phpbb_root_path . 'config.' . $phpEx);
  113. if (!defined('PHPBB_INSTALLED'))
  114. {
  115. // Redirect the user to the installer
  116. // We have to generate a full HTTP/1.1 header here since we can't guarantee to have any of the information
  117. // available as used by the redirect function
  118. $server_name = (!empty($_SERVER['HTTP_HOST'])) ? strtolower($_SERVER['HTTP_HOST']) : ((!empty($_SERVER['SERVER_NAME'])) ? $_SERVER['SERVER_NAME'] : getenv('SERVER_NAME'));
  119. $server_port = (!empty($_SERVER['SERVER_PORT'])) ? (int) $_SERVER['SERVER_PORT'] : (int) getenv('SERVER_PORT');
  120. $secure = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 1 : 0;
  121. $script_name = (!empty($_SERVER['PHP_SELF'])) ? $_SERVER['PHP_SELF'] : getenv('PHP_SELF');
  122. if (!$script_name)
  123. {
  124. $script_name = (!empty($_SERVER['REQUEST_URI'])) ? $_SERVER['REQUEST_URI'] : getenv('REQUEST_URI');
  125. }
  126. // Replace any number of consecutive backslashes and/or slashes with a single slash
  127. // (could happen on some proxy setups and/or Windows servers)
  128. $script_path = trim(dirname($script_name)) . '/install/index.' . $phpEx;
  129. $script_path = preg_replace('#[\\\\/]{2,}#', '/', $script_path);
  130. $url = (($secure) ? 'https://' : 'http://') . $server_name;
  131. if ($server_port && (($secure && $server_port <> 443) || (!$secure && $server_port <> 80)))
  132. {
  133. // HTTP HOST can carry a port number...
  134. if (strpos($server_name, ':') === false)
  135. {
  136. $url .= ':' . $server_port;
  137. }
  138. }
  139. $url .= $script_path;
  140. header('Location: ' . $url);
  141. exit;
  142. }
  143. if (defined('DEBUG_EXTRA'))
  144. {
  145. $base_memory_usage = 0;
  146. if (function_exists('memory_get_usage'))
  147. {
  148. $base_memory_usage = memory_get_usage();
  149. }
  150. }
  151. // Load Extensions
  152. if (!empty($load_extensions))
  153. {
  154. $load_extensions = explode(',', $load_extensions);
  155. foreach ($load_extensions as $extension)
  156. {
  157. @dl(trim($extension));
  158. }
  159. }
  160. // Include files
  161. require($phpbb_root_path . 'includes/acm/acm_' . $acm_type . '.' . $phpEx);
  162. require($phpbb_root_path . 'includes/cache.' . $phpEx);
  163. require($phpbb_root_path . 'includes/template.' . $phpEx);
  164. require($phpbb_root_path . 'includes/session.' . $phpEx);
  165. require($phpbb_root_path . 'includes/auth.' . $phpEx);
  166. require($phpbb_root_path . 'includes/functions.' . $phpEx);
  167. require($phpbb_root_path . 'includes/functions_content.' . $phpEx);
  168. require($phpbb_root_path . 'includes/constants.' . $phpEx);
  169. require($phpbb_root_path . 'includes/db/' . $dbms . '.' . $phpEx);
  170. require($phpbb_root_path . 'includes/utf/utf_tools.' . $phpEx);
  171. // Set PHP error handler to ours
  172. set_error_handler(defined('PHPBB_MSG_HANDLER') ? PHPBB_MSG_HANDLER : 'msg_handler');
  173. // Instantiate some basic classes
  174. $user = new user();
  175. $auth = new auth();
  176. $template = new template();
  177. $cache = new cache();
  178. $db = new $sql_db();
  179. // Connect to DB
  180. $db->sql_connect($dbhost, $dbuser, $dbpasswd, $dbname, $dbport, false, defined('PHPBB_DB_NEW_LINK') ? PHPBB_DB_NEW_LINK : false);
  181. // We do not need this any longer, unset for safety purposes
  182. unset($dbpasswd);
  183. // Grab global variables, re-cache if necessary
  184. $config = $cache->obtain_config();
  185. // www.phpBB-SEO.com SEO TOOLKIT BEGIN
  186. if (empty($phpbb_seo) ) {
  187. require_once($phpbb_root_path . 'phpbb_seo/phpbb_seo_class.'.$phpEx);
  188. $phpbb_seo = new phpbb_seo();
  189. }
  190. // www.phpBB-SEO.com SEO TOOLKIT END
  191. // Add own hook handler
  192. require($phpbb_root_path . 'includes/hooks/index.' . $phpEx);
  193. $phpbb_hook = new phpbb_hook(array('exit_handler', 'phpbb_user_session_handler', 'append_sid', array('template', 'display')));
  194. foreach ($cache->obtain_hooks() as $hook)
  195. {
  196. @include($phpbb_root_path . 'includes/hooks/' . $hook . '.' . $phpEx);
  197. }
  198. ?>