Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP Notice: Undefined index: HTTP_HOST #10973

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 5 additions & 2 deletions libraries/joomla/application/web.php
Expand Up @@ -848,6 +848,9 @@ protected function detectRequestUri()
$scheme = 'http://';
}

// Try to acquire the server host, if set.
$host = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : '';

/*
* There are some differences in the way that Apache and IIS populate server environment variables. To
* properly detect the requested URI we need to adjust our algorithm based on whether or not we are getting
Expand All @@ -860,13 +863,13 @@ protected function detectRequestUri()
if (!empty($_SERVER['PHP_SELF']) && !empty($_SERVER['REQUEST_URI']))
{
// The URI is built from the HTTP_HOST and REQUEST_URI environment variables in an Apache environment.
$uri = $scheme . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$uri = $scheme . $host . $_SERVER['REQUEST_URI'];
}
// If not in "Apache Mode" we will assume that we are in an IIS environment and proceed.
elseif (isset($_SERVER['HTTP_HOST']))
{
// IIS uses the SCRIPT_NAME variable instead of a REQUEST_URI variable... thanks, MS
$uri = $scheme . $_SERVER['HTTP_HOST'] . $_SERVER['SCRIPT_NAME'];
$uri = $scheme . $host . $_SERVER['SCRIPT_NAME'];

// If the QUERY_STRING variable exists append it to the URI string.
if (isset($_SERVER['QUERY_STRING']) && !empty($_SERVER['QUERY_STRING']))
Expand Down
7 changes: 5 additions & 2 deletions libraries/joomla/uri/uri.php
Expand Up @@ -72,6 +72,9 @@ public static function getInstance($uri = 'SERVER')
$https = '://';
}

// Try to acquire the server host, if set.
$host = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : '';

/*
* Since we are assigning the URI from the server variables, we first need
* to determine if we are running on apache or IIS. If PHP_SELF and REQUEST_URI
Expand All @@ -82,7 +85,7 @@ public static function getInstance($uri = 'SERVER')
{
// To build the entire URI we need to prepend the protocol, and the http host
// to the URI string.
$theURI = 'http' . $https . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$theURI = 'http' . $https . $host . $_SERVER['REQUEST_URI'];
}
else
{
Expand All @@ -93,7 +96,7 @@ public static function getInstance($uri = 'SERVER')
*
* IIS uses the SCRIPT_NAME variable instead of a REQUEST_URI variable... thanks, MS
*/
$theURI = 'http' . $https . $_SERVER['HTTP_HOST'] . $_SERVER['SCRIPT_NAME'];
$theURI = 'http' . $https . $host . $_SERVER['SCRIPT_NAME'];

// If the query string exists append it to the URI string
if (isset($_SERVER['QUERY_STRING']) && !empty($_SERVER['QUERY_STRING']))
Expand Down
5 changes: 3 additions & 2 deletions modules/mod_wrapper/helper.php
Expand Up @@ -44,8 +44,9 @@ public static function getParams(&$params)
// Adds 'http://' if none is set
if (substr($url, 0, 1) == '/')
{
// Relative url in component. use server http_host.
$url = 'http://' . $_SERVER['HTTP_HOST'] . $url;
// Relative url in component. use server http_host, if set.
$host = JFactory::getApplication()->input->server->getString('HTTP_HOST');
$url = 'http://' . $host . $url;
}
elseif (!strstr($url, 'http') && !strstr($url, 'https'))
{
Expand Down