Title: Undefined array key “HTTP_HOST”
Last modified: August 30, 2023

---

# Undefined array key “HTTP_HOST”

 *  Resolved [hakre](https://wordpress.org/support/users/hakre/)
 * (@hakre)
 * [2 years, 9 months ago](https://wordpress.org/support/topic/undefined-array-key-http_host-3/)
 * According to this support forum the issue is known, but for some reason I don’t
   understand, the topics are getting closed as resolved while it remains.
    - [Undefined array key “HTTP_HOST”](https://wordpress.org/support/topic/undefined-array-key-http_host/)
      by [makkabi](https://wordpress.org/support/users/makkabi/) [2 years, 2 months ago](https://wordpress.org/support/topic/undefined-array-key-http_host/)
    - [PHP notice when running wp-cron](https://wordpress.org/support/topic/php-notice-when-running-wp-cron-2/)
      by [hakre](https://wordpress.org/support/users/hakre/) (me) [1 year ago](https://wordpress.org/support/topic/php-notice-when-running-wp-cron-2/)
 * Vendor replies are always friendly, but for what remains, only adding confusion
   what the fix release politics are.
 * Therefore just another report against WP Simple 301 Redirects Version 2.0.8. 
   The script is parsed and executed by PHP 8.0.30 (cli).
 * When running in cron mode, this plugin spills a warning on the PHP SAPI diagnostic
   channel:
 * > PHP Warning: Undefined array key “HTTP_HOST” in /var/www/…/wp-content/plugins/
   > simple-301-redirects/wp-simple-301-redirects.php on line 173
 * **Please note:** In cron, any output, including the diagnostic channel, goes 
   into reporting. Just mentioning this, because it would be really helpful if this
   will be fixed upstream, so that upgrading the plugin would not lead again into
   noise in reporting.
 * This correlates to the get_address() function that accesses the PHP SAPI dependent
   $_SERVER array unchecked (line 173):
 *     ```wp-block-code
           164                 /**
           165                  * getAddress function
           166                  * utility function to get the full address of the current request
           167                  * credit: http://www.phpro.org/examples/Get-Full-URL.html
           168                  * @access public
           169                  * @return void
           170                  */
           171                 public function get_address() {
           172                         // return the full address
           173                         return $this->get_protocol().'://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
           174                 } // end function get_address
       ```
   
 * The fix is rather trivial in terms of warning suppression, just don’t access 
   $_SERVER array members if they do not exist. The directly following get_protocol()
   is an example of how such an isset()-check could look like (line 180 in the same
   file):
 *     ```wp-block-code
           175 
           176                 public function get_protocol() {
           177                         // Set the base protocol to http
           178                         $protocol = 'http';
           179                         // check for https
           180                         if ( isset( $_SERVER["HTTPS"] ) && strtolower( $_SERVER["HTTPS"] ) == "on" ) {
           181                                 $protocol .= "s";
           182                         }
           183 
           184                         return $protocol;
           185                 } // end function get_protocol
       ```
   
 * As both functions (methods) follow each other, we could assume that at least 
   one editor of that file – in past or present – did knew about a way to handle
   it (or at least were able by chance or accident). May I suggest to find out who
   it was and consult them if you need technical assistance with this?
 * If in case looking for an already reported fix, find the posting [makkabi](https://wordpress.org/support/users/makkabi/)
   by [1 year, 10 months ago](https://wordpress.org/support/topic/undefined-array-key-http_host/#post-14996959)
   suggesting to insert isset() checks.
 * Another fix is to prefix the dollar signs ($) that follow the string concatenation
   operator (.) with the error suppression operator (@) on that line, here as a 
   sed command line:
 *     ```wp-block-code
       $ sed -i '173s/\.\$/\.@\$/g' wp-content/plugins/simple-301-redirects/wp-simple-301-redirects.php
       # no output, sed (GNU sed) 4.2.2
       ```
   
 * As this continues to come up, it might require a plugin to patch this plugin,
   because it took now already more than two years and it seems that having Emojis
   in a plugin readme is of more importance and in the focus, perhaps on a level
   similar to friendly replies in the support forums. Which are nice, but it’s more
   than two years let alone reported in the Wordpess support forums.
 * Is there any intend to fix this? If so, how would the planning/scheduling of 
   it look like in terms of blockers and an estimation of fix release version/date?
   Do you have any needs or requirements? Do you accept patches for this (with a
   more serious fix)? Which PHP versions do you need to support?

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

 *  Plugin Support [AR Rasel](https://wordpress.org/support/users/arrasel403/)
 * (@arrasel403)
 * [2 years, 9 months ago](https://wordpress.org/support/topic/undefined-array-key-http_host-3/#post-17015379)
 * Hi [@hakre](https://wordpress.org/support/users/hakre/),
 * Hope you are doing well. Sorry for the inconvenience.
 * After getting the issue from your end (the second time), we released a newer 
   version plugin. And we were waiting for your update but we didn’t hear from you.
   And we assumed that the issue was already fixed. And as both are the same issue
   we resolved both topics.
 * However, as your issue is still not fixed. I am forwarding your issue to our 
   Dev Team again. They will look into this issue and we will try to fix it soon.
   Once we have fixed it we will inform you, don’t worry. Please allow us time to
   fix it.
 * Thanks for your patience!
 *  Plugin Support [Pial](https://wordpress.org/support/users/iapial/)
 * (@iapial)
 * [2 years, 8 months ago](https://wordpress.org/support/topic/undefined-array-key-http_host-3/#post-17093349)
 * Hello [@hakre](https://wordpress.org/support/users/hakre/) 
   Hope you are doing
   well. You will be glad to know we have fixed the “Undefined” issue on our Latest
   version of Simple 301 Redirects by BetterLinksPlease update to the Simple 301
   Redirects by BetterLinks v**2.0.9** and your issue will be resolvedPlease let
   me know how it goes Thanks
 *  Thread Starter [hakre](https://wordpress.org/support/users/hakre/)
 * (@hakre)
 * [2 years, 8 months ago](https://wordpress.org/support/topic/undefined-array-key-http_host-3/#post-17093926)
 * Hello [@iapial](https://wordpress.org/support/users/iapial/) (/cc [@arrasel403](https://wordpress.org/support/users/arrasel403/)),
   thanks for reaching out. What I can see in [https://github.com/WPDevelopers/simple-301-redirects/commit/d9aa6b0f885922c03f2be96487d95ac4a79e765f](https://github.com/WPDevelopers/simple-301-redirects/commit/d9aa6b0f885922c03f2be96487d95ac4a79e765f)
   looks good to me.
 * Not an issue that would render the change non-functional, nevertheless you may
   be interested that the expression
 *     ```wp-block-code
       ( isset( $_SERVER['HTTP_HOST'] ) && isset( $_SERVER['REQUEST_URI'] ) )
       ```
   
 * can be simplified in PHP as isset() supports multiple variables and only returns
   true when all are set. Example:
 *     ```wp-block-code
       isset( $_SERVER['HTTP_HOST'], $_SERVER['REQUEST_URI'] )
       ```
   
 * More details about isset() can be found in the PHP manual at [https://php.net/isset](https://php.net/isset).
    -  This reply was modified 2 years, 8 months ago by [hakre](https://wordpress.org/support/users/hakre/).
 *  Plugin Support [Pial](https://wordpress.org/support/users/iapial/)
 * (@iapial)
 * [2 years, 8 months ago](https://wordpress.org/support/topic/undefined-array-key-http_host-3/#post-17095616)
 * Hi [@hakre](https://wordpress.org/support/users/hakre/),
 * Hope you are doing well.
 * Thank you so much for your feedback. I am forwarding your recommendation to our
   Dev Team and they will look into this and take action as needed.
 * Really appreciate your support and feedback
   Have a wonderful day

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

The topic ‘Undefined array key “HTTP_HOST”’ is closed to new replies.

 * ![](https://ps.w.org/simple-301-redirects/assets/icon-256x256.jpg?rev=2783827)
 * [Simple 301 Redirects By BetterLinks - Easy WordPress Redirect Manager for Redirects, 404 Error Log & More](https://wordpress.org/plugins/simple-301-redirects/)
 * [Support Threads](https://wordpress.org/support/plugin/simple-301-redirects/)
 * [Active Topics](https://wordpress.org/support/plugin/simple-301-redirects/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/simple-301-redirects/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/simple-301-redirects/reviews/)

 * 5 replies
 * 3 participants
 * Last reply from: [Pial](https://wordpress.org/support/users/iapial/)
 * Last activity: [2 years, 8 months ago](https://wordpress.org/support/topic/undefined-array-key-http_host-3/#post-17095616)
 * Status: resolved