From 99ce7ba1df52334f11c6b97c3f24d0ed31c8f6d0 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Mon, 6 Aug 2012 22:16:45 +0200 Subject: Move serverHost and serverProtocol functions to OC_Request --- lib/request.php | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'lib/request.php') diff --git a/lib/request.php b/lib/request.php index 0b5aaf8ef30..cb93a088172 100644 --- a/lib/request.php +++ b/lib/request.php @@ -7,6 +7,51 @@ */ class OC_Request { + /** + * @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(OC::$CLI){ + return 'localhost'; + } + 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 Returns the server protocol + * @returns the server protocol + * + * Returns the server protocol. It respects reverse proxy servers and load balancers + */ + public static function serverProtocol() { + if (isset($_SERVER['HTTP_X_FORWARDED_PROTO'])) { + $proto = strtolower($_SERVER['HTTP_X_FORWARDED_PROTO']); + }else{ + if(isset($_SERVER['HTTPS']) and !empty($_SERVER['HTTPS']) and ($_SERVER['HTTPS']!='off')) { + $proto = 'https'; + }else{ + $proto = 'http'; + } + } + return($proto); + } + static public function isNoCache() { if (!isset($_SERVER['HTTP_CACHE_CONTROL'])) { return false; -- cgit v1.2.3