diff --git a/lib/helper.php b/lib/helper.php index efff00c2fe..6d7d1702aa 100755 --- a/lib/helper.php +++ b/lib/helper.php @@ -59,6 +59,28 @@ class OC_Helper { return $urlLinkTo; } + /** + * @brief Returns the server host + * @returns the server host + * + * Returns the server host, even if the website uses one or more + * reverse proxies + */ + public static function serverHost() { + if (isset($_SERVER['HTTP_X_FORWARDED_HOST'])) { + if (strpos($_SERVER['HTTP_X_FORWARDED_HOST'], ",") !== false) { + $host = trim(array_pop(explode(",", $_SERVER['HTTP_X_FORWARDED_HOST']))); + } + else{ + $host=$_SERVER['HTTP_X_FORWARDED_HOST']; + } + } + else{ + $host = $_SERVER['HTTP_HOST']; + } + return $host; + } + /** * @brief Creates an absolute url * @param $app app