mirror of
https://github.com/phpbb/phpbb.git
synced 2025-08-16 13:44:12 +02:00
[feature/request-class] Add server(), header() and is_ajax() to request
Extend the request class with helpers for reading server vars (server()) and HTTP request headers (header()). Refactor the existing code base to make use of these helpers, make $_SERVER a deactivated super global. Also introduce an is_ajax() method, which checks the X-Requested-With header for the value 'XMLHttpRequest', which is sent by JavaScript libraries, such as jQuery. PHPBB3-9716
This commit is contained in:
@@ -144,9 +144,9 @@ $db->sql_connect($dbhost, $dbuser, $dbpasswd, $dbname, $dbport, false, false);
|
||||
unset($dbpasswd);
|
||||
|
||||
$user->ip = '';
|
||||
if (!empty($_SERVER['REMOTE_ADDR']))
|
||||
if ($request->server('REMOTE_ADDR'))
|
||||
{
|
||||
$user->ip = (function_exists('phpbb_ip_normalise')) ? phpbb_ip_normalise($_SERVER['REMOTE_ADDR']) : htmlspecialchars($_SERVER['REMOTE_ADDR']);
|
||||
$user->ip = (function_exists('phpbb_ip_normalise')) ? phpbb_ip_normalise($request->server('REMOTE_ADDR')) : $request->server('REMOTE_ADDR', '', true);
|
||||
}
|
||||
|
||||
$sql = "SELECT config_value
|
||||
|
@@ -100,9 +100,9 @@ request_var('', 0, false, false, $request); // "dependency injection" for a func
|
||||
// Try and load an appropriate language if required
|
||||
$language = basename(request_var('language', ''));
|
||||
|
||||
if (!empty($_SERVER['HTTP_ACCEPT_LANGUAGE']) && !$language)
|
||||
if ($request->header('Accept-Language') && !$language)
|
||||
{
|
||||
$accept_lang_ary = explode(',', strtolower($_SERVER['HTTP_ACCEPT_LANGUAGE']));
|
||||
$accept_lang_ary = explode(',', strtolower($request->header('Accept-Language')));
|
||||
foreach ($accept_lang_ary as $accept_lang)
|
||||
{
|
||||
// Set correct format ... guess full xx_yy form
|
||||
@@ -428,15 +428,17 @@ class module
|
||||
*/
|
||||
function redirect($page)
|
||||
{
|
||||
// HTTP_HOST is having the correct browser url in most cases...
|
||||
$server_name = (!empty($_SERVER['HTTP_HOST'])) ? strtolower($_SERVER['HTTP_HOST']) : ((!empty($_SERVER['SERVER_NAME'])) ? $_SERVER['SERVER_NAME'] : getenv('SERVER_NAME'));
|
||||
$server_port = (!empty($_SERVER['SERVER_PORT'])) ? (int) $_SERVER['SERVER_PORT'] : (int) getenv('SERVER_PORT');
|
||||
$secure = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 1 : 0;
|
||||
global $request;
|
||||
|
||||
$script_name = (!empty($_SERVER['PHP_SELF'])) ? $_SERVER['PHP_SELF'] : getenv('PHP_SELF');
|
||||
// HTTP_HOST is having the correct browser url in most cases...
|
||||
$server_name = strtolower($request->header('Host', $request->server('SERVER_NAME')));
|
||||
$server_port = $request->server('SERVER_PORT', 0);
|
||||
$secure = ($request->server('HTTPS') == 'on') ? 1 : 0;
|
||||
|
||||
$script_name = $request->server('PHP_SELF');
|
||||
if (!$script_name)
|
||||
{
|
||||
$script_name = (!empty($_SERVER['REQUEST_URI'])) ? $_SERVER['REQUEST_URI'] : getenv('REQUEST_URI');
|
||||
$script_name = $request->server('REQUEST_URI');
|
||||
}
|
||||
|
||||
// Replace backslashes and doubled slashes (could happen on some proxy setups)
|
||||
|
@@ -999,7 +999,7 @@ class install_install extends module
|
||||
*/
|
||||
function obtain_advanced_settings($mode, $sub)
|
||||
{
|
||||
global $lang, $template, $phpEx;
|
||||
global $lang, $template, $phpEx, $request;
|
||||
|
||||
$this->page_title = $lang['STAGE_ADVANCED'];
|
||||
|
||||
@@ -1017,7 +1017,7 @@ class install_install extends module
|
||||
$s_hidden_fields .= '<input type="hidden" name="language" value="' . $data['language'] . '" />';
|
||||
|
||||
// HTTP_HOST is having the correct browser url in most cases...
|
||||
$server_name = (!empty($_SERVER['HTTP_HOST'])) ? strtolower($_SERVER['HTTP_HOST']) : ((!empty($_SERVER['SERVER_NAME'])) ? $_SERVER['SERVER_NAME'] : getenv('SERVER_NAME'));
|
||||
$server_name = strtolower($request->header('Host', $request->server('SERVER_NAME')));
|
||||
|
||||
// HTTP HOST can carry a port number...
|
||||
if (strpos($server_name, ':') !== false)
|
||||
@@ -1027,16 +1027,16 @@ class install_install extends module
|
||||
|
||||
$data['email_enable'] = ($data['email_enable'] !== '') ? $data['email_enable'] : true;
|
||||
$data['server_name'] = ($data['server_name'] !== '') ? $data['server_name'] : $server_name;
|
||||
$data['server_port'] = ($data['server_port'] !== '') ? $data['server_port'] : ((!empty($_SERVER['SERVER_PORT'])) ? (int) $_SERVER['SERVER_PORT'] : (int) getenv('SERVER_PORT'));
|
||||
$data['server_protocol'] = ($data['server_protocol'] !== '') ? $data['server_protocol'] : ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 'https://' : 'http://');
|
||||
$data['cookie_secure'] = ($data['cookie_secure'] !== '') ? $data['cookie_secure'] : ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? true : false);
|
||||
$data['server_port'] = ($data['server_port'] !== '') ? $data['server_port'] : $request->server('SERVER_PORT', 0);
|
||||
$data['server_protocol'] = ($data['server_protocol'] !== '') ? $data['server_protocol'] : ($request->server('HTTPS') == 'on' ? 'https://' : 'http://');
|
||||
$data['cookie_secure'] = ($data['cookie_secure'] !== '') ? $data['cookie_secure'] : ($request->server('HTTPS') == 'on' ? true : false);
|
||||
|
||||
if ($data['script_path'] === '')
|
||||
{
|
||||
$name = (!empty($_SERVER['PHP_SELF'])) ? $_SERVER['PHP_SELF'] : getenv('PHP_SELF');
|
||||
$name = $request->server('PHP_SELF');
|
||||
if (!$name)
|
||||
{
|
||||
$name = (!empty($_SERVER['REQUEST_URI'])) ? $_SERVER['REQUEST_URI'] : getenv('REQUEST_URI');
|
||||
$name = $request->server('REQUEST_URI');
|
||||
}
|
||||
|
||||
// Replace backslashes and doubled slashes (could happen on some proxy setups)
|
||||
@@ -1101,7 +1101,7 @@ class install_install extends module
|
||||
*/
|
||||
function load_schema($mode, $sub)
|
||||
{
|
||||
global $db, $lang, $template, $phpbb_root_path, $phpEx;
|
||||
global $db, $lang, $template, $phpbb_root_path, $phpEx, $request;
|
||||
|
||||
$this->page_title = $lang['STAGE_CREATE_TABLE'];
|
||||
$s_hidden_fields = '';
|
||||
@@ -1117,8 +1117,8 @@ class install_install extends module
|
||||
}
|
||||
|
||||
// HTTP_HOST is having the correct browser url in most cases...
|
||||
$server_name = (!empty($_SERVER['HTTP_HOST'])) ? strtolower($_SERVER['HTTP_HOST']) : ((!empty($_SERVER['SERVER_NAME'])) ? $_SERVER['SERVER_NAME'] : getenv('SERVER_NAME'));
|
||||
$referer = (!empty($_SERVER['HTTP_REFERER'])) ? strtolower($_SERVER['HTTP_REFERER']) : getenv('HTTP_REFERER');
|
||||
$server_name = strtolower($request->header('Host', $request->server('SERVER_NAME')));
|
||||
$referer = strtolower($request->header('Referer'));
|
||||
|
||||
// HTTP HOST can carry a port number...
|
||||
if (strpos($server_name, ':') !== false)
|
||||
@@ -1235,7 +1235,7 @@ class install_install extends module
|
||||
|
||||
$current_time = time();
|
||||
|
||||
$user_ip = (!empty($_SERVER['REMOTE_ADDR'])) ? phpbb_ip_normalise($_SERVER['REMOTE_ADDR']) : '';
|
||||
$user_ip = $request->server('REMOTE_ADDR') ? phpbb_ip_normalise($request->server('REMOTE_ADDR')) : '';
|
||||
|
||||
if ($data['script_path'] !== '/')
|
||||
{
|
||||
|
Reference in New Issue
Block a user