Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'core/Url.php')
-rw-r--r--core/Url.php48
1 files changed, 37 insertions, 11 deletions
diff --git a/core/Url.php b/core/Url.php
index 8d87f5e929..dbbf4dc98d 100644
--- a/core/Url.php
+++ b/core/Url.php
@@ -1,6 +1,6 @@
<?php
/**
- * Piwik - free/libre analytics platform
+ * Matomo - free/libre analytics platform
*
* @link https://matomo.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
@@ -9,7 +9,7 @@
namespace Piwik;
use Exception;
-use Piwik\Network\IPUtils;
+use Matomo\Network\IPUtils;
/**
* Provides URL related helper methods.
@@ -208,11 +208,14 @@ class Url
}
if ($host === false) {
- $host = @$_SERVER['HTTP_HOST'];
+ $host = self::getHostFromServerNameVar();
if (empty($host)) {
- // if no current host, assume valid
-
- return true;
+ // fallback to old behaviour
+ $host = @$_SERVER['HTTP_HOST'];
+ if (empty($host)) {
+ // if no current host, assume valid
+ return true;
+ }
}
}
@@ -298,12 +301,18 @@ class Url
*/
public static function getHost($checkIfTrusted = true)
{
- // HTTP/1.1 request
- if (isset($_SERVER['HTTP_HOST'])
+ if (strlen($host = self::getHostFromServerNameVar())) {
+ // if server_name is set we don't want to look at HTTP_HOST
+
+ if (!$checkIfTrusted || self::isValidHost($host)) {
+ return $host;
+ }
+ } elseif (isset($_SERVER['HTTP_HOST'])
&& strlen($host = $_SERVER['HTTP_HOST'])
&& (!$checkIfTrusted
|| self::isValidHost($host))
) {
+ // HTTP/1.1 request
return $host;
}
@@ -322,7 +331,9 @@ class Url
*/
public static function setHost($host)
{
+ $_SERVER['SERVER_NAME'] = $host;
$_SERVER['HTTP_HOST'] = $host;
+ unset($_SERVER['SERVER_PORT']);
}
/**
@@ -373,7 +384,7 @@ class Url
}
/**
- * Returns an array mapping query paramater names with query parameter values for
+ * Returns an array mapping query parameter names with query parameter values for
* the current URL.
*
* @return array If current URL is `"http://example.org/dir1/dir2/index.php?param1=value1&param2=value2"`
@@ -613,8 +624,8 @@ class Url
*/
public static function getHostSanitized($host)
{
- if (!class_exists("Piwik\\Network\\IPUtils")) {
- throw new Exception("Piwik\\Network\\IPUtils could not be found, maybe you are using Matomo from git and need to update Composer. $ php composer.phar update");
+ if (!class_exists("Matomo\\Network\\IPUtils")) {
+ throw new Exception("Matomo\\Network\\IPUtils could not be found, maybe you are using Matomo from git and need to update Composer. $ php composer.phar update");
}
return IPUtils::sanitizeIp($host);
}
@@ -761,4 +772,19 @@ class Url
$assume_secure_protocol = @Config::getInstance()->General['assume_secure_protocol'];
return (bool) $assume_secure_protocol;
}
+
+ public static function getHostFromServerNameVar()
+ {
+ $host = @$_SERVER['SERVER_NAME'];
+ if (!empty($host)) {
+ if (strpos($host, ':') === false
+ && !empty($_SERVER['SERVER_PORT'])
+ && $_SERVER['SERVER_PORT'] != 80
+ && $_SERVER['SERVER_PORT'] != 443
+ ) {
+ $host .= ':' . $_SERVER['SERVER_PORT'];
+ }
+ }
+ return $host;
+ }
}