]> source.dussan.org Git - nextcloud-server.git/commitdiff
Add method OC_Helper::serverHost()
authorDaniele E. Domenichelli <daniele.domenichelli@gmail.com>
Thu, 12 Apr 2012 12:35:28 +0000 (14:35 +0200)
committerRobin Appelman <icewind@owncloud.com>
Thu, 12 Apr 2012 15:51:17 +0000 (17:51 +0200)
This method returns the server host, even if the website uses one or
more reverse proxies.

lib/helper.php

index efff00c2fe6eb23498a8d39946f089cb2f4abcac..6d7d1702aa85ec7a8cdf76976f5623368aa2028c 100755 (executable)
@@ -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