Skip to content

Commit 2d4dab9

Browse files
committed
Fix port issue (behind load balancer) SAML-Toolkits#57
1 parent 24ff0de commit 2d4dab9

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

lib/Saml2/Utils.php

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -260,19 +260,14 @@ public static function getSelfURLhost()
260260
$protocol = 'http';
261261
}
262262

263-
if (isset($_SERVER["SERVER_PORT"])) {
263+
if (isset($_SERVER["X-Forwarded-Port"])) {
264+
$portnumber = $_SERVER["X-Forwarded-Port"];
265+
} else if (isset($_SERVER["SERVER_PORT"])) {
264266
$portnumber = $_SERVER["SERVER_PORT"];
265-
$port = ':' . $portnumber;
267+
}
266268

267-
if ($protocol == 'http') {
268-
if ($portnumber == '80') {
269-
$port = '';
270-
}
271-
} elseif ($protocol == 'https') {
272-
if ($portnumber == '443') {
273-
$port = '';
274-
}
275-
}
269+
if (isset($portnumber) && ($portnumber != '80') && ($portnumber != '443')) {
270+
$port = ':' . $portnumber;
276271
}
277272

278273
return $protocol."://" . $currenthost . $port;

0 commit comments

Comments
 (0)