diff --git a/inc/init.php b/inc/init.php
index ed44097297c461bc2507bc0cbaf7da7cc1ba269c..3b438f15b4595c6c43c3f610c7fe186b949fb5c5 100644
--- a/inc/init.php
+++ b/inc/init.php
@@ -419,12 +419,16 @@ function getBaseURL($abs=null){
     if($conf['baseurl']) return rtrim($conf['baseurl'],'/').$dir;
 
     //split hostheader into host and port
-    $addr = explode(':',$_SERVER['HTTP_HOST']);
-    $host = $addr[0];
-    $port = '';
-    if (isset($addr[1])) {
-        $port = $addr[1];
-    } elseif (isset($_SERVER['SERVER_PORT'])) {
+    if(isset($_SERVER['HTTP_HOST'])){
+        list($host,$port) = explode(':',$_SERVER['HTTP_HOST']);
+    }elseif(isset($_SERVER['SERVER_NAME'])){
+        list($host,$port) = explode(':',$_SERVER['SERVER_NAME']);
+    }else{
+        $host = php_uname('n');
+        $port = '';
+    }
+
+    if(!$port && isset($_SERVER['SERVER_PORT'])) {
         $port = $_SERVER['SERVER_PORT'];
     }
     if(!is_ssl()){