diff --git a/include/config_default.inc.php b/include/config_default.inc.php index 3818cfd57..19b110da1 100644 --- a/include/config_default.inc.php +++ b/include/config_default.inc.php @@ -638,6 +638,12 @@ $conf['picture_url_style'] = 'id'; // tags is not unique, all tags with the same url representation will be shown $conf['tag_url_style'] = 'id-tag'; +// force an explicit port in the url (like ":80" or ":443") +// * 'none' : do not add any port, whatever protocol is detected +// * 'auto' : tries to smartly add a port based on $_SERVER variables +// * 123 : adds ":123" next to url host +$conf['url_port'] = 'none'; + // +-----------------------------------------------------------------------+ // | tags | // +-----------------------------------------------------------------------+ diff --git a/include/functions_url.inc.php b/include/functions_url.inc.php index 1e66d527c..d6cbc3227 100644 --- a/include/functions_url.inc.php +++ b/include/functions_url.inc.php @@ -32,6 +32,7 @@ function get_root_url() */ function get_absolute_root_url($with_scheme=true) { + global $conf; // TODO - add HERE the possibility to call PWG functions from external scripts // Support X-Forwarded-Proto header for HTTPS detection in PHP @@ -61,15 +62,30 @@ 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 = null; + + if ('none' == $conf['url_port']) { - $url_port = ':'.$_SERVER['SERVER_PORT']; - if (strrchr($url, ':') != $url_port) + // do nothing + } + elseif ('auto' == $conf['url_port']) + { + if ((!$is_https && $_SERVER['SERVER_PORT'] != 80) || ($is_https && $_SERVER['SERVER_PORT'] != 443)) { - $url .= $url_port; + $url_port = ':'.$_SERVER['SERVER_PORT']; } } + else + { + // we have a custom port + $url_port = ':'.$conf['url_port']; + } + + if (!empty($url_port) and strrchr($url, ':') != $url_port) + { + $url .= $url_port; + } } } $url .= cookie_path();