From a1bf3411e488b65c78f8ead6265f7578fc8e8022 Mon Sep 17 00:00:00 2001 From: Tim van Dijen <tvdijen@gmail.com> Date: Sun, 21 Jan 2018 10:19:50 +0100 Subject: [PATCH] rewrite getServerPort Also fixes edge-case situation where $_SERVER['SERVER_PORT'] is not set for an HTTPS connection, this function would return an explicit port 80 i.e. ":80" rather than an empty string. --- lib/SimpleSAML/Utils/HTTP.php | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/lib/SimpleSAML/Utils/HTTP.php b/lib/SimpleSAML/Utils/HTTP.php index d14d71e5a..88eadf5c4 100644 --- a/lib/SimpleSAML/Utils/HTTP.php +++ b/lib/SimpleSAML/Utils/HTTP.php @@ -108,15 +108,11 @@ class HTTP */ public static function getServerPort() { - $port = (isset($_SERVER['SERVER_PORT'])) ? $_SERVER['SERVER_PORT'] : '80'; - if (self::getServerHTTPS()) { - if ($port !== '443') { - return ':'.$port; - } - } else { - if ($port !== '80') { - return ':'.$port; - } + $default_port = self::getServerHTTPS() ? '443' : '80'; + $port = isset($_SERVER['SERVER_PORT']) ? $_SERVER['SERVER_PORT'] : $default_port; + + if ($port !== $default_port) { + return ':'.$port; } return ''; } -- GitLab