From 59d3c52cd47f907aded243bf1acabc9f70548e42 Mon Sep 17 00:00:00 2001 From: Dimasites Date: Sat, 24 Feb 2024 01:08:48 +0300 Subject: [PATCH] Fix working with port in default config --- core/docs/config.inc.tpl | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/core/docs/config.inc.tpl b/core/docs/config.inc.tpl index b3ae24f2e7d..c658abdc0f3 100644 --- a/core/docs/config.inc.tpl +++ b/core/docs/config.inc.tpl @@ -52,7 +52,7 @@ if(defined('PHP_SAPI') && (PHP_SAPI == "cli" || PHP_SAPI == "embed")) { $isSecureRequest = ((isset($_SERVER['HTTPS']) && !empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off') || $_SERVER['SERVER_PORT'] == $https_port); } if (!defined('MODX_URL_SCHEME')) { - $url_scheme= $isSecureRequest ? 'https://' : 'http://'; + $url_scheme = $isSecureRequest ? 'https://' : 'http://'; define('MODX_URL_SCHEME', $url_scheme); } if (!defined('MODX_HTTP_HOST')) { @@ -60,11 +60,9 @@ if (!defined('MODX_HTTP_HOST')) { $http_host = '{http_host}'; define('MODX_HTTP_HOST', $http_host); } else { - $http_host= array_key_exists('HTTP_HOST', $_SERVER) ? htmlspecialchars($_SERVER['HTTP_HOST'], ENT_QUOTES) : '{http_host}'; - if ($_SERVER['SERVER_PORT'] !== 80) { - $http_host = str_replace(':' . $_SERVER['SERVER_PORT'], '', $http_host); - } - $http_host .= in_array($_SERVER['SERVER_PORT'], [80, 443]) ? '' : ':' . $_SERVER['SERVER_PORT']; + $http_host = array_key_exists('HTTP_HOST', $_SERVER) ? parse_url($url_scheme . $_SERVER['HTTP_HOST'], PHP_URL_HOST) : '{http_host}'; + $http_port = parse_url($url_scheme . $_SERVER['HTTP_HOST'], PHP_URL_PORT) ?: $_SERVER['SERVER_PORT']; + $http_host .= in_array($http_port, [80, 443]) ? '' : ':' . $http_port; define('MODX_HTTP_HOST', $http_host); } }