Blame Extras/phpBB/3.0.4/common.php

4c79b5
4c79b5
/**
4c79b5
*
4c79b5
* @package phpBB3
4c79b5
* @version $Id: common.php 8760 2008-08-15 19:46:51Z aptx $
4c79b5
* @copyright (c) 2005 phpBB Group
4c79b5
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
4c79b5
*
4c79b5
* Minimum Requirement: PHP 4.3.3
4c79b5
*/
4c79b5
4c79b5
/**
4c79b5
*/
4c79b5
if (!defined('IN_PHPBB'))
4c79b5
{
4c79b5
	exit;
4c79b5
}
4c79b5
4c79b5
$starttime = explode(' ', microtime());
4c79b5
$starttime = $starttime[1] + $starttime[0];
4c79b5
4c79b5
// Report all errors, except notices
4c79b5
error_reporting(E_ALL ^ E_NOTICE);
4c79b5
4c79b5
/*
4c79b5
* Remove variables created by register_globals from the global scope
4c79b5
* Thanks to Matt Kavanagh
4c79b5
*/
4c79b5
function deregister_globals()
4c79b5
{
4c79b5
	$not_unset = array(
4c79b5
		'GLOBALS'	=> true,
4c79b5
		'_GET'		=> true,
4c79b5
		'_POST'		=> true,
4c79b5
		'_COOKIE'	=> true,
4c79b5
		'_REQUEST'	=> true,
4c79b5
		'_SERVER'	=> true,
4c79b5
		'_SESSION'	=> true,
4c79b5
		'_ENV'		=> true,
4c79b5
		'_FILES'	=> true,
4c79b5
		'phpEx'		=> true,
4c79b5
		'phpbb_root_path'	=> true
4c79b5
	);
4c79b5
4c79b5
	// Not only will array_merge and array_keys give a warning if
4c79b5
	// a parameter is not an array, array_merge will actually fail.
4c79b5
	// So we check if _SESSION has been initialised.
4c79b5
	if (!isset($_SESSION) || !is_array($_SESSION))
4c79b5
	{
4c79b5
		$_SESSION = array();
4c79b5
	}
4c79b5
4c79b5
	// Merge all into one extremely huge array; unset this later
4c79b5
	$input = array_merge(
4c79b5
		array_keys($_GET),
4c79b5
		array_keys($_POST),
4c79b5
		array_keys($_COOKIE),
4c79b5
		array_keys($_SERVER),
4c79b5
		array_keys($_SESSION),
4c79b5
		array_keys($_ENV),
4c79b5
		array_keys($_FILES)
4c79b5
	);
4c79b5
4c79b5
	foreach ($input as $varname)
4c79b5
	{
4c79b5
		if (isset($not_unset[$varname]))
4c79b5
		{
4c79b5
			// Hacking attempt. No point in continuing unless it's a COOKIE
4c79b5
			if ($varname !== 'GLOBALS' || isset($_GET['GLOBALS']) || isset($_POST['GLOBALS']) || isset($_SERVER['GLOBALS']) || isset($_SESSION['GLOBALS']) || isset($_ENV['GLOBALS']) || isset($_FILES['GLOBALS']))
4c79b5
			{
4c79b5
				exit;
4c79b5
			}
4c79b5
			else
4c79b5
			{
4c79b5
				$cookie = &$_COOKIE;
4c79b5
				while (isset($cookie['GLOBALS']))
4c79b5
				{
4c79b5
					foreach ($cookie['GLOBALS'] as $registered_var => $value)
4c79b5
					{
4c79b5
						if (!isset($not_unset[$registered_var]))
4c79b5
						{
4c79b5
							unset($GLOBALS[$registered_var]);
4c79b5
						}
4c79b5
					}
4c79b5
					$cookie = &$cookie['GLOBALS'];
4c79b5
				}
4c79b5
			}
4c79b5
		}
4c79b5
4c79b5
		unset($GLOBALS[$varname]);
4c79b5
	}
4c79b5
4c79b5
	unset($input);
4c79b5
}
4c79b5
4c79b5
// If we are on PHP >= 6.0.0 we do not need some code
4c79b5
if (version_compare(PHP_VERSION, '6.0.0-dev', '>='))
4c79b5
{
4c79b5
	/**
4c79b5
	* @ignore
4c79b5
	*/
4c79b5
	define('STRIP', false);
4c79b5
}
4c79b5
else
4c79b5
{
4c79b5
	@set_magic_quotes_runtime(0);
4c79b5
4c79b5
	// Be paranoid with passed vars
4c79b5
	if (@ini_get('register_globals') == '1' || strtolower(@ini_get('register_globals')) == 'on' || !function_exists('ini_get'))
4c79b5
	{
4c79b5
		deregister_globals();
4c79b5
	}
4c79b5
4c79b5
	define('STRIP', (get_magic_quotes_gpc()) ? true : false);
4c79b5
}
4c79b5
4c79b5
if (defined('IN_CRON'))
4c79b5
{
4c79b5
	$phpbb_root_path = dirname(__FILE__) . DIRECTORY_SEPARATOR;
4c79b5
}
4c79b5
4c79b5
if (!file_exists($phpbb_root_path . 'config.' . $phpEx))
4c79b5
{
4c79b5
	die("

The config.$phpEx file could not be found.

Click here to install phpBB

");
4c79b5
}
4c79b5
4c79b5
require($phpbb_root_path . 'config.' . $phpEx);
4c79b5
4c79b5
if (!defined('PHPBB_INSTALLED'))
4c79b5
{
4c79b5
	// Redirect the user to the installer
4c79b5
	// We have to generate a full HTTP/1.1 header here since we can't guarantee to have any of the information
4c79b5
	// available as used by the redirect function
4c79b5
	$server_name = (!empty($_SERVER['HTTP_HOST'])) ? strtolower($_SERVER['HTTP_HOST']) : ((!empty($_SERVER['SERVER_NAME'])) ? $_SERVER['SERVER_NAME'] : getenv('SERVER_NAME'));
4c79b5
	$server_port = (!empty($_SERVER['SERVER_PORT'])) ? (int) $_SERVER['SERVER_PORT'] : (int) getenv('SERVER_PORT');
4c79b5
	$secure = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 1 : 0;
4c79b5
4c79b5
	$script_name = (!empty($_SERVER['PHP_SELF'])) ? $_SERVER['PHP_SELF'] : getenv('PHP_SELF');
4c79b5
	if (!$script_name)
4c79b5
	{
4c79b5
		$script_name = (!empty($_SERVER['REQUEST_URI'])) ? $_SERVER['REQUEST_URI'] : getenv('REQUEST_URI');
4c79b5
	}
4c79b5
4c79b5
	// Replace any number of consecutive backslashes and/or slashes with a single slash
4c79b5
	// (could happen on some proxy setups and/or Windows servers)
4c79b5
	$script_path = trim(dirname($script_name)) . '/install/index.' . $phpEx;
4c79b5
	$script_path = preg_replace('#[\\\\/]{2,}#', '/', $script_path);
4c79b5
4c79b5
	$url = (($secure) ? 'https://' : 'http://') . $server_name;
4c79b5
4c79b5
	if ($server_port && (($secure && $server_port <> 443) || (!$secure && $server_port <> 80)))
4c79b5
	{
4c79b5
		// HTTP HOST can carry a port number...
4c79b5
		if (strpos($server_name, ':') === false)
4c79b5
		{
4c79b5
			$url .= ':' . $server_port;
4c79b5
		}
4c79b5
	}
4c79b5
4c79b5
	$url .= $script_path;
4c79b5
	header('Location: ' . $url);
4c79b5
	exit;
4c79b5
}
4c79b5
4c79b5
if (defined('DEBUG_EXTRA'))
4c79b5
{
4c79b5
	$base_memory_usage = 0;
4c79b5
	if (function_exists('memory_get_usage'))
4c79b5
	{
4c79b5
		$base_memory_usage = memory_get_usage();
4c79b5
	}
4c79b5
}
4c79b5
4c79b5
// Load Extensions
4c79b5
if (!empty($load_extensions))
4c79b5
{
4c79b5
	$load_extensions = explode(',', $load_extensions);
4c79b5
4c79b5
	foreach ($load_extensions as $extension)
4c79b5
	{
4c79b5
		@dl(trim($extension));
4c79b5
	}
4c79b5
}
4c79b5
4c79b5
// Include files
4c79b5
require($phpbb_root_path . 'includes/acm/acm_' . $acm_type . '.' . $phpEx);
4c79b5
require($phpbb_root_path . 'includes/cache.' . $phpEx);
4c79b5
require($phpbb_root_path . 'includes/template.' . $phpEx);
4c79b5
require($phpbb_root_path . 'includes/session.' . $phpEx);
4c79b5
require($phpbb_root_path . 'includes/auth.' . $phpEx);
4c79b5
4c79b5
require($phpbb_root_path . 'includes/functions.' . $phpEx);
4c79b5
require($phpbb_root_path . 'includes/functions_content.' . $phpEx);
4c79b5
4c79b5
require($phpbb_root_path . 'includes/constants.' . $phpEx);
4c79b5
require($phpbb_root_path . 'includes/db/' . $dbms . '.' . $phpEx);
4c79b5
require($phpbb_root_path . 'includes/utf/utf_tools.' . $phpEx);
4c79b5
4c79b5
// Set PHP error handler to ours
4c79b5
set_error_handler(defined('PHPBB_MSG_HANDLER') ? PHPBB_MSG_HANDLER : 'msg_handler');
4c79b5
4c79b5
// Instantiate some basic classes
4c79b5
$user		= new user();
4c79b5
$auth		= new auth();
4c79b5
$template	= new template();
4c79b5
$cache		= new cache();
4c79b5
$db			= new $sql_db();
4c79b5
4c79b5
// Connect to DB
4c79b5
$db->sql_connect($dbhost, $dbuser, $dbpasswd, $dbname, $dbport, false, defined('PHPBB_DB_NEW_LINK') ? PHPBB_DB_NEW_LINK : false);
4c79b5
4c79b5
// We do not need this any longer, unset for safety purposes
4c79b5
unset($dbpasswd);
4c79b5
4c79b5
// Grab global variables, re-cache if necessary
4c79b5
$config = $cache->obtain_config();
4c79b5
4c79b5
// Add own hook handler
4c79b5
require($phpbb_root_path . 'includes/hooks/index.' . $phpEx);
4c79b5
$phpbb_hook = new phpbb_hook(array('exit_handler', 'phpbb_user_session_handler', 'append_sid', array('template', 'display')));
4c79b5
4c79b5
foreach ($cache->obtain_hooks() as $hook)
4c79b5
{
4c79b5
	@include($phpbb_root_path . 'includes/hooks/' . $hook . '.' . $phpEx);
4c79b5
}
4c79b5
4c79b5
?>