commit da751e0f92e7038e2fb7eae1b021092908d252ff
Author: Francois Marier <francois@catalyst.net.nz>
Date:   Tue Sep 23 15:25:52 2008 +1200

    MDL-11061 hack to fix the qualified_me() bug
    
    This needs to be done properly, but it will work for now.
    
    It requires an extra configuration variable in config.php: wwwserver
    
    For example:
    
      $CFG->wwwroot   = 'https://example.com/moodle';
      $CFG->wwwserver = 'https://example.com';

diff --git a/lib/weblib.php b/lib/weblib.php
index 9bd350f..a02ce96 100644
--- a/lib/weblib.php
+++ b/lib/weblib.php
@@ -251,47 +251,7 @@ function get_referer($stripquery=true) {
 function qualified_me() {
 
     global $CFG;
-
-    if (!empty($CFG->wwwroot)) {
-        $url = parse_url($CFG->wwwroot);
-    }
-
-    if (!empty($url['host'])) {
-        $hostname = $url['host'];
-    } else if (!empty($_SERVER['SERVER_NAME'])) {
-        $hostname = $_SERVER['SERVER_NAME'];
-    } else if (!empty($_ENV['SERVER_NAME'])) {
-        $hostname = $_ENV['SERVER_NAME'];
-    } else if (!empty($_SERVER['HTTP_HOST'])) {
-        $hostname = $_SERVER['HTTP_HOST'];
-    } else if (!empty($_ENV['HTTP_HOST'])) {
-        $hostname = $_ENV['HTTP_HOST'];
-    } else {
-        notify('Warning: could not find the name of this server!');
-        return false;
-    }
-
-    if (!empty($url['port'])) {
-        $hostname .= ':'.$url['port'];
-    } else if (!empty($_SERVER['SERVER_PORT'])) {
-        if ($_SERVER['SERVER_PORT'] != 80 && $_SERVER['SERVER_PORT'] != 443) {
-            $hostname .= ':'.$_SERVER['SERVER_PORT'];
-        }
-    }
-
-    // TODO, this does not work in the situation described in MDL-11061, but
-    // I don't know how to fix it. Possibly believe $CFG->wwwroot ahead of what
-    // the server reports.
-    if (isset($_SERVER['HTTPS'])) {
-        $protocol = ($_SERVER['HTTPS'] == 'on') ? 'https://' : 'http://';
-    } else if (isset($_SERVER['SERVER_PORT'])) { # Apache2 does not export $_SERVER['HTTPS']
-        $protocol = ($_SERVER['SERVER_PORT'] == '443') ? 'https://' : 'http://';
-    } else {
-        $protocol = 'http://';
-    }
-
-    $url_prefix = $protocol.$hostname;
-    return $url_prefix . me();
+    return $CFG->wwwserver . me();
 }
 
 
