From 0fbba118f0da25379e016149506c97ae9a3872d8 Mon Sep 17 00:00:00 2001
From: Olav Morken <olav.morken@uninett.no>
Date: Wed, 29 Jul 2009 12:12:09 +0000
Subject: [PATCH] Fix code for determining the current hostname.

git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@1595 44740490-163a-0410-bde0-09ae8108e29a
---
 lib/SimpleSAML/Utilities.php | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/lib/SimpleSAML/Utilities.php b/lib/SimpleSAML/Utilities.php
index 5dfd4d051..2e823a24a 100644
--- a/lib/SimpleSAML/Utilities.php
+++ b/lib/SimpleSAML/Utilities.php
@@ -15,7 +15,15 @@ class SimpleSAML_Utilities {
 	 */
 	public static function getSelfHost() {
 	
-		$currenthost = $_SERVER['HTTP_HOST'];
+		if (array_key_exists('HTTP_HOST', $_SERVER)) {
+			$currenthost = $_SERVER['HTTP_HOST'];
+		} elseif (array_key_exists('SERVER_NAME', $_SERVER)) {
+			$currenthost = $_SERVER['SERVER_NAME'];
+		} else {
+			/* Almost certainly not what you want, but ... */
+			$currenthost = 'localhost';
+		}
+
 		if(strstr($currenthost, ":")) {
 				$currenthostdecomposed = explode(":", $currenthost);
 				$currenthost = $currenthostdecomposed[0];
-- 
GitLab