includes/startup.php
changeset 0 ceef6d64c21d
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/includes/startup.php	Wed Mar 07 16:41:10 2012 +0400
     1.3 @@ -0,0 +1,150 @@
     1.4 +<?php
     1.5 +/**
     1.6 +*
     1.7 +* @package phpBB3
     1.8 +* @copyright (c) 2011 phpBB Group
     1.9 +* @license http://opensource.org/licenses/gpl-license.php GNU Public License
    1.10 +*
    1.11 +*/
    1.12 +
    1.13 +/**
    1.14 +*/
    1.15 +if (!defined('IN_PHPBB'))
    1.16 +{
    1.17 +	exit;
    1.18 +}
    1.19 +
    1.20 +// Report all errors, except notices and deprecation messages
    1.21 +if (!defined('E_DEPRECATED'))
    1.22 +{
    1.23 +	define('E_DEPRECATED', 8192);
    1.24 +}
    1.25 +error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED);
    1.26 +
    1.27 +/*
    1.28 +* Remove variables created by register_globals from the global scope
    1.29 +* Thanks to Matt Kavanagh
    1.30 +*/
    1.31 +function deregister_globals()
    1.32 +{
    1.33 +	$not_unset = array(
    1.34 +		'GLOBALS'	=> true,
    1.35 +		'_GET'		=> true,
    1.36 +		'_POST'		=> true,
    1.37 +		'_COOKIE'	=> true,
    1.38 +		'_REQUEST'	=> true,
    1.39 +		'_SERVER'	=> true,
    1.40 +		'_SESSION'	=> true,
    1.41 +		'_ENV'		=> true,
    1.42 +		'_FILES'	=> true,
    1.43 +		'phpEx'		=> true,
    1.44 +		'phpbb_root_path'	=> true
    1.45 +	);
    1.46 +
    1.47 +	// Not only will array_merge and array_keys give a warning if
    1.48 +	// a parameter is not an array, array_merge will actually fail.
    1.49 +	// So we check if _SESSION has been initialised.
    1.50 +	if (!isset($_SESSION) || !is_array($_SESSION))
    1.51 +	{
    1.52 +		$_SESSION = array();
    1.53 +	}
    1.54 +
    1.55 +	// Merge all into one extremely huge array; unset this later
    1.56 +	$input = array_merge(
    1.57 +		array_keys($_GET),
    1.58 +		array_keys($_POST),
    1.59 +		array_keys($_COOKIE),
    1.60 +		array_keys($_SERVER),
    1.61 +		array_keys($_SESSION),
    1.62 +		array_keys($_ENV),
    1.63 +		array_keys($_FILES)
    1.64 +	);
    1.65 +
    1.66 +	foreach ($input as $varname)
    1.67 +	{
    1.68 +		if (isset($not_unset[$varname]))
    1.69 +		{
    1.70 +			// Hacking attempt. No point in continuing unless it's a COOKIE (so a cookie called GLOBALS doesn't lock users out completely)
    1.71 +			if ($varname !== 'GLOBALS' || isset($_GET['GLOBALS']) || isset($_POST['GLOBALS']) || isset($_SERVER['GLOBALS']) || isset($_SESSION['GLOBALS']) || isset($_ENV['GLOBALS']) || isset($_FILES['GLOBALS']))
    1.72 +			{
    1.73 +				exit;
    1.74 +			}
    1.75 +			else
    1.76 +			{
    1.77 +				$cookie = &$_COOKIE;
    1.78 +				while (isset($cookie['GLOBALS']))
    1.79 +				{
    1.80 +					if (!is_array($cookie['GLOBALS']))
    1.81 +					{
    1.82 +						break;
    1.83 +					}
    1.84 +
    1.85 +					foreach ($cookie['GLOBALS'] as $registered_var => $value)
    1.86 +					{
    1.87 +						if (!isset($not_unset[$registered_var]))
    1.88 +						{
    1.89 +							unset($GLOBALS[$registered_var]);
    1.90 +						}
    1.91 +					}
    1.92 +					$cookie = &$cookie['GLOBALS'];
    1.93 +				}
    1.94 +			}
    1.95 +		}
    1.96 +
    1.97 +		unset($GLOBALS[$varname]);
    1.98 +	}
    1.99 +
   1.100 +	unset($input);
   1.101 +}
   1.102 +
   1.103 +// Register globals and magic quotes have been dropped in PHP 5.4
   1.104 +if (version_compare(PHP_VERSION, '5.4.0-dev', '>='))
   1.105 +{
   1.106 +	/**
   1.107 +	* @ignore
   1.108 +	*/
   1.109 +	define('STRIP', false);
   1.110 +}
   1.111 +else
   1.112 +{
   1.113 +	@set_magic_quotes_runtime(0);
   1.114 +
   1.115 +	// Be paranoid with passed vars
   1.116 +	if (@ini_get('register_globals') == '1' || strtolower(@ini_get('register_globals')) == 'on' || !function_exists('ini_get'))
   1.117 +	{
   1.118 +		deregister_globals();
   1.119 +	}
   1.120 +
   1.121 +	define('STRIP', (get_magic_quotes_gpc()) ? true : false);
   1.122 +}
   1.123 +
   1.124 +// Prevent date/time functions from throwing E_WARNING on PHP 5.3 by setting a default timezone
   1.125 +if (function_exists('date_default_timezone_set') && function_exists('date_default_timezone_get'))
   1.126 +{
   1.127 +	// For PHP 5.1.0 the date/time functions have been rewritten
   1.128 +	// and setting a timezone is required prior to calling any date/time function.
   1.129 +
   1.130 +	// Since PHP 5.2.0 calls to date/time functions without having a timezone set
   1.131 +	// result in E_STRICT errors being thrown.
   1.132 +	// Note: We already exclude E_STRICT errors
   1.133 +	// (to be exact: they are not included in E_ALL in PHP 5.2)
   1.134 +
   1.135 +	// In PHP 5.3.0 the error level has been raised to E_WARNING which causes problems
   1.136 +	// because we show E_WARNING errors and do not set a default timezone.
   1.137 +	// This is because we have our own timezone handling and work in UTC only anyway.
   1.138 +
   1.139 +	// So what we basically want to do is set our timezone to UTC,
   1.140 +	// but we don't know what other scripts (such as bridges) are involved,
   1.141 +	// so we check whether a timezone is already set by calling date_default_timezone_get().
   1.142 +
   1.143 +	// Unfortunately, date_default_timezone_get() itself might throw E_WARNING
   1.144 +	// if no timezone has been set, so we have to keep it quiet with @.
   1.145 +
   1.146 +	// date_default_timezone_get() tries to guess the correct timezone first
   1.147 +	// and then falls back to UTC when everything fails.
   1.148 +	// We just set the timezone to whatever date_default_timezone_get() returns.
   1.149 +	date_default_timezone_set(@date_default_timezone_get());
   1.150 +}
   1.151 +
   1.152 +$starttime = explode(' ', microtime());
   1.153 +$starttime = $starttime[1] + $starttime[0];