Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-27796

$_REQUEST['HTTP_HOST'] not set

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 2.0.3
    • Fix Version/s: 2.1.1
    • Component/s: Administration
    • Labels:
    • Environment:
      Apache, virtualhosts, RHEL5 to be specific.
    • Database:
      Any
    • Testing Instructions:
      Hide

      Configure apache somehow to not populate HTTP_HOST (not really sure how our vhost setup did that...)

      or use good old telnet and type HTTP 1.0 style GET request

      Show
      Configure apache somehow to not populate HTTP_HOST (not really sure how our vhost setup did that...) or use good old telnet and type HTTP 1.0 style GET request
    • Workaround:
      Hide

      I should think http://php.net/parse_url and $_SERVER['PHP_SELF'] would be better than hand-rolling all this, but perhaps PHP_SELF is not consistently populated either...

      So just fixing the immediate buglet:

      This patch is un-tested, actually. The array() might need to be array('host'=>null) instead.

      Index: setuplib.php
      ===================================================================
      — setuplib.php (revision 5)
      +++ setuplib.php (working copy)
      @@ -725,7 +725,7 @@
      */
      function setup_get_remote_url() {
      $rurl = array();

      • list($rurl['host']) = explode(':', $_SERVER['HTTP_HOST']);
        + list($rurl['host']) = isset($_SERVER['HTTP_HOST']) ? explode(':', $_SERVER['HTTP_HOST']) : array();
        $rurl['port'] = $_SERVER['SERVER_PORT'];
        $rurl['path'] = $_SERVER['SCRIPT_NAME']; // Script path without slash arguments
        $rurl['scheme'] = (empty($_SERVER['HTTPS']) or $_SERVER['HTTPS'] === 'off' or $_SERVER['HTTPS'] === 'Off' or $_SERVER['HTTPS'] === 'OFF') ? 'http' : 'https';
      Show
      I should think http://php.net/parse_url and $_SERVER ['PHP_SELF'] would be better than hand-rolling all this, but perhaps PHP_SELF is not consistently populated either... So just fixing the immediate buglet: This patch is un-tested, actually. The array() might need to be array('host'=>null) instead. Index: setuplib.php =================================================================== — setuplib.php (revision 5) +++ setuplib.php (working copy) @@ -725,7 +725,7 @@ */ function setup_get_remote_url() { $rurl = array(); list($rurl ['host'] ) = explode(':', $_SERVER ['HTTP_HOST'] ); + list($rurl ['host'] ) = isset($_SERVER ['HTTP_HOST'] ) ? explode(':', $_SERVER ['HTTP_HOST'] ) : array(); $rurl ['port'] = $_SERVER ['SERVER_PORT'] ; $rurl ['path'] = $_SERVER ['SCRIPT_NAME'] ; // Script path without slash arguments $rurl ['scheme'] = (empty($_SERVER ['HTTPS'] ) or $_SERVER ['HTTPS'] === 'off' or $_SERVER ['HTTPS'] === 'Off' or $_SERVER ['HTTPS'] === 'OFF') ? 'http' : 'https';
    • Affected Branches:
      MOODLE_20_STABLE
    • Fixed Branches:
      MOODLE_21_STABLE
    • Pull from Repository:
    • Pull Master Branch:
      w29_MDL-27796_m22_httphost

      Description

      PHP Notice: Undefined index: HTTP_HOST in /var/www/html/example.com/moodle_versions/r5/lib/setuplib.php on line 728

      Moodle seems to function just fine without the 'host' setting so far, so this is just an annoyance in the logs to us.

        Gliffy Diagrams

          Attachments

            Activity

            Hide
            richardlynch Richard Lynch added a comment -

            An annoyance that recurs every 2 to 3 seconds, however, with some ajax-y thing on the Moodle "home" page...

            Show
            richardlynch Richard Lynch added a comment - An annoyance that recurs every 2 to 3 seconds, however, with some ajax-y thing on the Moodle "home" page...
            Hide
            salvetore Michael de Raadt added a comment -

            Thanks for reporting this.

            Show
            salvetore Michael de Raadt added a comment - Thanks for reporting this.
            Hide
            richardlynch Richard Lynch added a comment -

            Aha!

            I believe we set things up originally by IP address, and out of a developer's home directory, for lack of proper DNS entries.
            (Ops was quite busy that day.)

            "Skip to main content
            Incorrect access detected, this server may be accessed only through "http://10.8.31.21/~john.doe/moodle" address, sorry.
            Please notify server administrator.
            (Continue)"

            This should make it easy to reproduce if you need to...

            That said, there are probably other configurations one can manage in httpd.conf to make this happen as well, so it's probably a "common edge case" versus "extremely rare whack edge case"

            Show
            richardlynch Richard Lynch added a comment - Aha! I believe we set things up originally by IP address, and out of a developer's home directory, for lack of proper DNS entries. (Ops was quite busy that day.) "Skip to main content Incorrect access detected, this server may be accessed only through "http://10.8.31.21/~john.doe/moodle" address, sorry. Please notify server administrator. (Continue)" This should make it easy to reproduce if you need to... That said, there are probably other configurations one can manage in httpd.conf to make this happen as well, so it's probably a "common edge case" versus "extremely rare whack edge case"
            Hide
            skodak Petr Skoda added a comment -

            This problem will appear also when you access server with a really old browser that is using HTTP/1.0 headers.

            Thanks a lot for the report.

            Show
            skodak Petr Skoda added a comment - This problem will appear also when you access server with a really old browser that is using HTTP/1.0 headers. Thanks a lot for the report.
            Hide
            samhemelryk Sam Hemelryk added a comment -

            Thanks guys, this has been integrated now

            Show
            samhemelryk Sam Hemelryk added a comment - Thanks guys, this has been integrated now
            Hide
            dongsheng Dongsheng Cai added a comment -

            Tested with telnet using following header:
            GET /moodletest/test.php HTTP/1.0
            User-Agent: Mozilla/4.0
            Accept: /

            normally it should contain "Host: dongsheng.moodle.local"

            It worked.

            Show
            dongsheng Dongsheng Cai added a comment - Tested with telnet using following header: GET /moodletest/test.php HTTP/1.0 User-Agent: Mozilla/4.0 Accept: / normally it should contain "Host: dongsheng.moodle.local" It worked.
            Hide
            skodak Petr Skoda added a comment -

            Thanks everybody, this is now part of the weekly build.

            Show
            skodak Petr Skoda added a comment - Thanks everybody, this is now part of the weekly build.
            Hide
            richardlynch Richard Lynch added a comment -

            THANK YOU!!!
            I've closed out the ticket on our internal tracker, and look forward to seeing the patch coming back down-stream.

            Show
            richardlynch Richard Lynch added a comment - THANK YOU!!! I've closed out the ticket on our internal tracker, and look forward to seeing the patch coming back down-stream.

              People

              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Fix Release Date:
                  1/Aug/11