From 5627186c2f8b450460892f0247dbbb5f8d4369b4 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sat, 18 Dec 2010 10:07:04 +0100 Subject: more robust hostname detection as discussed in http://www.freelists.org/post/dokuwiki/git-changes-20101209,7 --- inc/init.php | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'inc/init.php') diff --git a/inc/init.php b/inc/init.php index ed4409729..3b438f15b 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()){ -- cgit v1.2.3 From 204b27c8e0c1bcfa6810ee45bd12fda3f5d83960 Mon Sep 17 00:00:00 2001 From: Michael Hamann Date: Sun, 16 Jan 2011 22:23:54 +0100 Subject: Fix getBaseURL for literal IPv6 addresses in URLs (RFC 2732) + test case --- inc/init.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'inc/init.php') diff --git a/inc/init.php b/inc/init.php index 3b438f15b..6f4ba1ca9 100644 --- a/inc/init.php +++ b/inc/init.php @@ -420,9 +420,13 @@ function getBaseURL($abs=null){ //split hostheader into host and port if(isset($_SERVER['HTTP_HOST'])){ - list($host,$port) = explode(':',$_SERVER['HTTP_HOST']); + $parsed_host = parse_url('http://'.$_SERVER['HTTP_HOST']); + $host = $parsed_host['host']; + $port = $parsed_host['port']; }elseif(isset($_SERVER['SERVER_NAME'])){ - list($host,$port) = explode(':',$_SERVER['SERVER_NAME']); + $parsed_host = parse_url('http://'.$_SERVER['SERVER_NAME']); + $host = $parsed_host['host']; + $port = $parsed_host['port']; }else{ $host = php_uname('n'); $port = ''; @@ -431,6 +435,11 @@ function getBaseURL($abs=null){ if(!$port && isset($_SERVER['SERVER_PORT'])) { $port = $_SERVER['SERVER_PORT']; } + + if(is_null($port)){ + $port = ''; + } + if(!is_ssl()){ $proto = 'http://'; if ($port == '80') { -- cgit v1.2.3