Add method OC_Helper::serverHost()

This method returns the server host, even if the website uses one or
more reverse proxies.
This commit is contained in:
Daniele E. Domenichelli 2012-04-12 14:35:28 +02:00 committed by Robin Appelman
parent 0466437fa7
commit 7b5395675d
1 changed files with 22 additions and 0 deletions

View File

@ -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