From d58534e8779dd9b4a6ac5386428ae562bc0b5fab Mon Sep 17 00:00:00 2001 From: Tobias Ollmann Date: Wed, 16 Sep 2015 19:23:20 +0200 Subject: Use HTTP_X_FORWARDED_HOST if available This enables piwigo to be run e.g. in a docker container behind a proxy. If HTTP_X_FORWARDED_HOST is not set, HTTP_HOST is used as usual --- include/functions_url.inc.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/include/functions_url.inc.php b/include/functions_url.inc.php index 5a471bc10..9cc6c9ec7 100644 --- a/include/functions_url.inc.php +++ b/include/functions_url.inc.php @@ -62,7 +62,14 @@ function get_absolute_root_url($with_scheme=true) { $url .= 'http://'; } - $url .= $_SERVER['HTTP_HOST']; + if (isset($_SERVER['HTTP_X_FORWARDED_HOST'])) + { + $url .= $_SERVER['HTTP_X_FORWARDED_HOST']; + } + else + { + $url .= $_SERVER['HTTP_HOST']; + } if ( (!$is_https && $_SERVER['SERVER_PORT'] != 80) ||($is_https && $_SERVER['SERVER_PORT'] != 443)) { -- cgit v1.2.3 From 6d01f33d9fa973c6209c1e6350aeea429b4c31b9 Mon Sep 17 00:00:00 2001 From: Tobias Ollmann Date: Thu, 17 Sep 2015 19:44:45 +0200 Subject: Do not add the server port when sitting behind a proxy. Assume that Http-X-Forwarded-Host is set correctly --- include/functions_url.inc.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/include/functions_url.inc.php b/include/functions_url.inc.php index 9cc6c9ec7..138a895e1 100644 --- a/include/functions_url.inc.php +++ b/include/functions_url.inc.php @@ -69,14 +69,14 @@ function get_absolute_root_url($with_scheme=true) else { $url .= $_SERVER['HTTP_HOST']; - } - if ( (!$is_https && $_SERVER['SERVER_PORT'] != 80) - ||($is_https && $_SERVER['SERVER_PORT'] != 443)) - { - $url_port = ':'.$_SERVER['SERVER_PORT']; - if (strrchr($url, ':') != $url_port) + if ( (!$is_https && $_SERVER['SERVER_PORT'] != 80) + ||($is_https && $_SERVER['SERVER_PORT'] != 443)) { - $url .= $url_port; + $url_port = ':'.$_SERVER['SERVER_PORT']; + if (strrchr($url, ':') != $url_port) + { + $url .= $url_port; + } } } } -- cgit v1.2.3