• Resolved hakre

    (@hakre)


    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.

    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):

        164                 /**
        165                  * getAddress function
        166                  * utility function to get the full address of the current request
        167                  * credit: https://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):

        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 by 1 year, 10 months ago 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:

    $ 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

    (@arrasel403)

    Hi @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

    (@iapial)

    Hello @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 BetterLinks

    Please update to the Simple 301 Redirects by BetterLinks v2.0.9 and your issue will be resolved

    Please let me know how it goes
    Thanks

    Thread Starter hakre

    (@hakre)

    Hello @iapial (/cc @arrasel403), thanks for reaching out. What I can see in 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

    ( 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:

    isset( $_SERVER['HTTP_HOST'], $_SERVER['REQUEST_URI'] )

    More details about isset() can be found in the PHP manual at https://php.net/isset .

    • This reply was modified 1 year, 5 months ago by hakre.
    Plugin Support Pial

    (@iapial)

    Hi @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.