Support » Fixing WordPress » PHP Notice: Undefined index HTTP_HOST

  • Hi,
    I read a lot about this php warnings that we often found in the debug.log file:

    PHP Notice: Undefined index HTTP_HOST

    In the other forum posts the problem is always related to a specific plugin, but in this case I would like to highlight that these warnings are also related to wordpress core.

    This is an exmaple of the warnings I found everyday in the debug.log file. To collect more information about the request I have traced the $_SERVER variables, But I do not understand why wordpress throws these warnings.
    (N.B. real server path, folder and uri has been removed).

    [20-Jul-2020 07:26:19 UTC] Array
    (
        [SERVER_SOFTWARE] => Apache
        [REQUEST_URI] => /
        [PHP_INI_SCAN_DIR] => 
        [PATH] => /usr/local/jdk/bin:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin:/usr/local/bin:/usr/X11R6/bin:/root/bin:/opt/bin
        [PWD] => /usr/local/cpanel/cgi-sys
        [TZ] => Europe/Rome
        [SHLVL] => 0
        [MAGICK_THREAD_LIMIT] => 1
        [PHP_FCGI_MAX_REQUESTS] => 150000
        [HTTP_CONNECTION] => close
        [SCRIPT_NAME] => /index.php
        [QUERY_STRING] => 
        [REQUEST_METHOD] => GET
        [SERVER_PROTOCOL] => HTTP/1.0
        [GATEWAY_INTERFACE] => CGI/1.1
        [REMOTE_PORT] => 64315
        [SCRIPT_FILENAME] => /home/xxxx/public_html/index.php
        [SERVER_ADMIN] => webmaster@myurl.com
        [CONTEXT_DOCUMENT_ROOT] => /home/myfolder/public_html
        [CONTEXT_PREFIX] => 
        [REQUEST_SCHEME] => http
        [DOCUMENT_ROOT] => /home/myfolder/public_html
        [REMOTE_ADDR] => 45.76.157.210
        [SERVER_PORT] => 80
        [SERVER_ADDR] => my server ip address
        [SERVER_NAME] => my server name
        [SERVER_SIGNATURE] => 
        [SCRIPT_URI] => my server uri
        [SCRIPT_URL] => /
        [UNIQUE_ID] => XxVHG8twg@6e5mHOH0R6CAAAAHM
        [FCGI_ROLE] => RESPONDER
        [PHP_SELF] => /index.php
        [REQUEST_TIME_FLOAT] => 1595229979.61
        [REQUEST_TIME] => 1595229979
        [argv] => Array
            (
            )
    
        [argc] => 0
    )
    
    [20-Jul-2020 07:26:19 UTC] PHP Notice:  Undefined index: HTTP_HOST in /home/myfolder/public_html/wp-includes/ms-settings.php on line 57
    [20-Jul-2020 07:26:20 UTC] PHP Notice:  Undefined index: host in /home/myfolder/public_html/wp-includes/canonical.php on line 536
    [20-Jul-2020 07:26:20 UTC] PHP Notice:  Undefined index: host in /home/myfolder/public_html/wp-includes/canonical.php on line 537
    [20-Jul-2020 07:26:20 UTC] PHP Notice:  Undefined index: host in /home/myfolder/public_html/wp-includes/canonical.php on line 537
    [20-Jul-2020 07:26:20 UTC] PHP Notice:  Undefined index: host in /home/myfolder/public_html/wp-includes/canonical.php on line 538
    [20-Jul-2020 07:26:20 UTC] PHP Notice:  Undefined index: host in /home/myfolder/public_html/wp-includes/canonical.php on line 541

    I mean, why wordpress does not check if http_host exists before using it?
    And more specifically, which could be the origin of the problem?
    Maybe would be a security concern?

    I ‘ve also read that this warnings could be related to a connection made without a browser.
    Any help would be appreciated, thanks in advance.

Viewing 1 replies (of 1 total)
  • For wp-includes/canonical.php 536
    Change

    if ( strtolower( $original['host'] ) == strtolower( $redirect['host'] ) ||
    		( strtolower( $original['host'] ) != 'www.' . strtolower( $redirect['host'] ) && 'www.' . strtolower( $original['host'] ) != strtolower( $redirect['host'] ) ) ) {
    		$redirect['host'] = $original['host'];
    	}

    to

    if ( ! isset( $original['host'] ) ) {
    // fixing notice host
    $original['host'] = '';
    }
    if ( strtolower( $original['host'] ) == strtolower( $redirect['host'] ) ||
    		( strtolower( $original['host'] ) != 'www.' . strtolower( $redirect['host'] ) && 'www.' . strtolower( $original['host'] ) != strtolower( $redirect['host'] ) ) ) {
    		$redirect['host'] = $original['host'];
    	}

    For ms-settings.php i’m at the work

    • This reply was modified 3 years, 8 months ago by autotutorial.
Viewing 1 replies (of 1 total)
  • The topic ‘PHP Notice: Undefined index HTTP_HOST’ is closed to new replies.