diff --git a/core/docs/config.inc.tpl b/core/docs/config.inc.tpl index 8ef1913a7b1..b3ae24f2e7d 100644 --- a/core/docs/config.inc.tpl +++ b/core/docs/config.inc.tpl @@ -57,14 +57,14 @@ if (!defined('MODX_URL_SCHEME')) { } if (!defined('MODX_HTTP_HOST')) { if(defined('PHP_SAPI') && (PHP_SAPI == "cli" || PHP_SAPI == "embed")) { - $http_host='{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); // remove port from HTTP_HOST + if ($_SERVER['SERVER_PORT'] !== 80) { + $http_host = str_replace(':' . $_SERVER['SERVER_PORT'], '', $http_host); } - $http_host .= ($_SERVER['SERVER_PORT'] == 80 || $isSecureRequest) ? '' : ':' . $_SERVER['SERVER_PORT']; + $http_host .= in_array($_SERVER['SERVER_PORT'], [80, 443]) ? '' : ':' . $_SERVER['SERVER_PORT']; define('MODX_HTTP_HOST', $http_host); } } diff --git a/setup/includes/config/modconfigreader.class.php b/setup/includes/config/modconfigreader.class.php index d7373bea2b4..772e870f5ff 100644 --- a/setup/includes/config/modconfigreader.class.php +++ b/setup/includes/config/modconfigreader.class.php @@ -69,13 +69,13 @@ public function loadDefaults(array $config = array()) { */ public function getHttpHost() { if (php_sapi_name() != 'cli') { - $this->config['https_port'] = isset ($_POST['httpsport']) ? $_POST['httpsport'] : '443'; + $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']; + $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']); /* remove port from HTTP_HOST */ + $this->config['http_host'] = str_replace(':' . $_SERVER['SERVER_PORT'], '', $this->config['http_host']); } - $this->config['http_host'] .= ($_SERVER['SERVER_PORT'] == 80 || $isSecureRequest) ? '' : ':' . $_SERVER['SERVER_PORT']; + $this->config['http_host'] .= in_array($_SERVER['SERVER_PORT'], [80, 443]) ? '' : ':' . $_SERVER['SERVER_PORT']; } else { $this->config['http_host'] = 'localhost'; $this->config['https_port'] = 443; diff --git a/setup/index.php b/setup/index.php index f99ec587155..c76e3b81a96 100644 --- a/setup/index.php +++ b/setup/index.php @@ -62,10 +62,12 @@ } if (!$isCommandLine) { $https = isset($_SERVER['HTTPS']) ? $_SERVER['HTTPS'] : false; - $installBaseUrl= (!$https || strtolower($https) != 'on') ? 'http://' : 'https://'; + $installBaseUrl = (!$https || strtolower($https) != 'on') ? 'http://' : 'https://'; $installBaseUrl .= $_SERVER['HTTP_HOST']; - if (isset($_SERVER['SERVER_PORT']) && (string)$_SERVER['SERVER_PORT'] != '' && $_SERVER['SERVER_PORT'] != 80) $installBaseUrl= str_replace(':' . $_SERVER['SERVER_PORT'], '', $installBaseUrl); - $installBaseUrl .= ($_SERVER['SERVER_PORT'] == 80 || ($https !== false || strtolower($https) == 'on')) ? '' : ':' . $_SERVER['SERVER_PORT']; + if (isset($_SERVER['SERVER_PORT']) && (string)$_SERVER['SERVER_PORT'] !== '' && $_SERVER['SERVER_PORT'] !== 80) { + $installBaseUrl = str_replace(':' . $_SERVER['SERVER_PORT'], '', $installBaseUrl); + } + $installBaseUrl .= in_array($_SERVER['SERVER_PORT'], [80, 443]) ? '' : ':' . $_SERVER['SERVER_PORT']; $installBaseUrl .= $_SERVER['SCRIPT_NAME']; $installBaseUrl = htmlspecialchars($installBaseUrl, ENT_QUOTES, 'utf-8'); define('MODX_SETUP_URL', $installBaseUrl);