Title: Set default value for $_SERVER[&#8216;HTTP_HOST&#8217;]
Last modified: March 24, 2023

---

# Set default value for $_SERVER[‘HTTP_HOST’]

 *  Resolved [p15h](https://wordpress.org/support/users/prestonwordsworth/)
 * (@prestonwordsworth)
 * [3 years, 2 months ago](https://wordpress.org/support/topic/set-default-value-for-_serverhttp_host/)
 * Dear Majumder
 * We’ve recently observed this error log message a couple times:
 *     ```wp-block-code
       'PHP message: PHP Warning:  Undefined array key "HTTP_HOST" in /home/www/htdocs/wp-content/advanced-cache.php on line 12; PHP message: PHP Warning:  Undefined array key "HTTP_HOST" in /home/www/htdocs/wp-content/advanced-cache.php on line 13; PHP message: PHP Warning:  Undefined array key "HTTP_HOST" in /home/www/htdocs/wp-content/advanced-cache.php on line 200'
       ```
   
 * Per the wp-cli handbook, the [fix](https://make.wordpress.org/cli/handbook/guides/common-issues/#php-notice-undefined-index-on-_server-superglobal)
   seems to be to add something to advanced-cache.php along the lines of:
 *     ```wp-block-code
       if ( ! isset( $_SERVER['HTTP_HOST'] ) ) {
           $_SERVER['HTTP_HOST'] = 'example.com';
       }
       ```
   
 * I wonder what your thoughts are on this.

Viewing 6 replies - 1 through 6 (of 6 total)

 *  Plugin Contributor [iSaumya](https://wordpress.org/support/users/isaumya/)
 * (@isaumya)
 * [3 years, 2 months ago](https://wordpress.org/support/topic/set-default-value-for-_serverhttp_host/#post-16591691)
 * Hi [@prestonwordsworth](https://wordpress.org/support/users/prestonwordsworth/),
   
   We can’t go with that approach, as that value is specifically needed for the 
   plugin to work as it is used in many places. So, hardcoding it with some specific
   domain would be a really bad idea as the plugin is used across multiple domains.
   Rather, I think it is best for you to see why that value is not there in the 
   first place as it is supposed to be there.
 *  Thread Starter [p15h](https://wordpress.org/support/users/prestonwordsworth/)
 * (@prestonwordsworth)
 * [3 years, 2 months ago](https://wordpress.org/support/topic/set-default-value-for-_serverhttp_host/#post-16591793)
 * You’re absolutely right, [@isaumya](https://wordpress.org/support/users/isaumya/).
   I was wondering too why the value isn’t there in the first place. The WP-CLI 
   handbook, however, has this to say:
 * > The `$_SERVER` superglobal is an array typically populated by a web server 
   > with information such as headers, paths, and script locations. PHP CLI doesn’t
   > populate this variable, nor does WP-CLI, because many of the variable details
   > are meaningless at the command line.
 * Which appears to imply the superglobal isn’t populated by default. Do you know
   where $_SERVER is supposed to be defined?
 * Our fix for now is to do the hardcoding in wp-config.php, which seems to be what
   they advise.
 *  Plugin Contributor [iSaumya](https://wordpress.org/support/users/isaumya/)
 * (@isaumya)
 * [3 years, 2 months ago](https://wordpress.org/support/topic/set-default-value-for-_serverhttp_host/#post-16591988)
 * Hi [@prestonwordsworth](https://wordpress.org/support/users/prestonwordsworth/),
   
   The super global is populated at the server level at the time of processing PHP
   requests. Moreover this plugin does nothing over CLI. It only process request
   that actually comes though the browser, I mean real user requests for which the
   super global is supposed to be there.
 *  Thread Starter [p15h](https://wordpress.org/support/users/prestonwordsworth/)
 * (@prestonwordsworth)
 * [3 years, 2 months ago](https://wordpress.org/support/topic/set-default-value-for-_serverhttp_host/#post-16593443)
 * Thanks for putting us on the right avenue, [@isaumya](https://wordpress.org/support/users/isaumya/)!
   For the benefit of those who may have stumbled on the same thing in their error
   log, [here’s](https://www.php.net/manual/en/reserved.variables.server.php) the
   relevant doc:
 * > PHP will create additional elements with values from request headers. These
   > entries will be named `HTTP_` followed by the header name, capitalized and 
   > with underscores instead of hyphens. For example, the `Accept-Language` header
   > would be available as `$_SERVER['HTTP_ACCEPT_LANGUAGE']`.
 * So ‘HTTP_HOST’ is contents of the Host: header from the current request, if present.
 * In our specific case, the request came from a user agent belonging to our hosting
   company. My suspicion is the request was sent directly to our ip address, hence
   the lack of a Host: header.
 *  Thread Starter [p15h](https://wordpress.org/support/users/prestonwordsworth/)
 * (@prestonwordsworth)
 * [3 years, 1 month ago](https://wordpress.org/support/topic/set-default-value-for-_serverhttp_host/#post-16650806)
 * Turns out this was caused by bots scanning the site by directly visiting our 
   ip address, which would naturally circumvent CF’s hostname-based WAF. Such traffic
   can be blocked at server level like this:
 *     ```wp-block-code
       SetEnvIfNoCase Host "^\d|^$" bot
   
   
       # Controls who can get stuff from this server.
   
           	<RequireAll>
                   Require all granted
                   Require not env bot
           	</RequireAll>
       ```
   
 *  Plugin Contributor [iSaumya](https://wordpress.org/support/users/isaumya/)
 * (@isaumya)
 * [3 years, 1 month ago](https://wordpress.org/support/topic/set-default-value-for-_serverhttp_host/#post-16651405)
 * Hi [@prestonwordsworth](https://wordpress.org/support/users/prestonwordsworth/),
   
   That’s a good finding. Thanks for sharing the server rule for others.

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Set default value for $_SERVER[‘HTTP_HOST’]’ is closed to new replies.

 * ![](https://ps.w.org/wp-cloudflare-page-cache/assets/icon-256x256.gif?rev=3234997)
 * [Super Page Cache – Cloudflare Cache, Page Speed & Core Web Vitals](https://wordpress.org/plugins/wp-cloudflare-page-cache/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wp-cloudflare-page-cache/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wp-cloudflare-page-cache/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-cloudflare-page-cache/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-cloudflare-page-cache/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-cloudflare-page-cache/reviews/)

## Tags

 * [HTTP_HOST](https://wordpress.org/support/topic-tag/http_host/)

 * 6 replies
 * 2 participants
 * Last reply from: [iSaumya](https://wordpress.org/support/users/isaumya/)
 * Last activity: [3 years, 1 month ago](https://wordpress.org/support/topic/set-default-value-for-_serverhttp_host/#post-16651405)
 * Status: resolved