[dokuwiki] Re: git changes 2010-12-09

  • From: Robin Getz <robin.getz@xxxxxxxxxx>
  • To: dokuwiki@xxxxxxxxxxxxx
  • Date: Fri, 17 Dec 2010 11:29:36 -0500

On Thu 16 Dec 2010 14:36, Andreas Gohr pondered:
> > I grok that - the point I was trying to make is that in the future, in a
> > different subsystem (not mail), may run into the same issue. Better to
> > make a general fix - isn't it?
> 
> Yeah I understood your intentions. But: if this other system expects
> an URL there and gets back example.com and uses that to build some
> link it will fail for sure.

Yep, lieing to the system is always a bad idea...

How about using php_uname('n') instead?

> If it gets back ./ and constructs a link 
> from that, it might have a tiny chance to work as a relative link...
> so much on my rationale.

OK - this should work both from the web and the command line interface.
It will not give the proper virtual host (since at the command line you don't 
know that), but it will give the proper machine name - which like you stated, 
should have a better chance of working than "example.com" - even in mail :)


diff --git a/inc/init.php b/inc/init.php
index 36bbf68..2f5a198 100644
--- a/inc/init.php
+++ b/inc/init.php
@@ -423,8 +423,14 @@ function getBaseURL($abs=null){
     if($conf['baseurl']) return rtrim($conf['baseurl'],'/').$dir;
 
     //split hostheader into host and port
-    $addr = explode(':',$_SERVER['HTTP_HOST']);
+    if (isset($_SERVER['SERVER_NAME'])) {
+        $addr = explode(':',$_SERVER['SERVER_NAME']);
+    } else {
+        $addr = explode(':',$_SERVER['HTTP_HOST']);
     $host = $addr[0];
+    if(!$host) $host = php_uname('n');
+
     $port = '';
     if (isset($addr[1])) {
         $port = $addr[1];


-- 
DokuWiki mailing list - more info at
http://www.dokuwiki.org/mailinglist

Other related posts: