From c1b07afa53e222a97c716db5a493282a4f866717 Mon Sep 17 00:00:00 2001 From: Dimasites Date: Sat, 24 Feb 2024 01:08:56 +0300 Subject: [PATCH] Fix working with port in setup --- setup/includes/config/modconfigreader.class.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/setup/includes/config/modconfigreader.class.php b/setup/includes/config/modconfigreader.class.php index 772e870f5ff..b6e4a38b0d6 100644 --- a/setup/includes/config/modconfigreader.class.php +++ b/setup/includes/config/modconfigreader.class.php @@ -71,11 +71,10 @@ public function getHttpHost() { if (php_sapi_name() != 'cli') { $this->config['https_port'] = isset($_POST['httpsport']) ? $_POST['httpsport'] : 443; $isSecureRequest = ((isset($_SERVER['HTTPS']) && !empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off') || $_SERVER['SERVER_PORT'] == $this->config['https_port']); - $this->config['http_host'] = $_SERVER['HTTP_HOST']; - if ($_SERVER['SERVER_PORT'] != 80) { - $this->config['http_host'] = str_replace(':' . $_SERVER['SERVER_PORT'], '', $this->config['http_host']); - } - $this->config['http_host'] .= in_array($_SERVER['SERVER_PORT'], [80, 443]) ? '' : ':' . $_SERVER['SERVER_PORT']; + $url_scheme = $isSecureRequest ? 'https://' : 'http://'; + $this->config['http_host'] = parse_url($url_scheme . $_SERVER['HTTP_HOST'], PHP_URL_HOST); + $this->config['http_port'] = parse_url($url_scheme . $_SERVER['PHP_URL_PORT'], PHP_URL_HOST) ?: $_SERVER['SERVER_PORT']; + $this->config['http_host'] .= in_array($this->config['http_port'], [80, 443]) ? '' : ':' . $this->config['http_port']; } else { $this->config['http_host'] = 'localhost'; $this->config['https_port'] = 443;