PageRenderTime 28ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 1ms

/zafenio/common.php

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