Make WordPress Core

Opened 9 years ago

Last modified 3 weeks ago

#34353 reopened defect (bug)

redirect_canonical() – Undefined indexes 'host' and 'scheme'

Reported by: theamila's profile theamila Owned by:
Milestone: Future Release Priority: normal
Severity: normal Version: 4.3.1
Component: Canonical Keywords: needs-unit-tests has-patch needs-testing-info
Focuses: Cc:

Description

Hello,
We have a problem on our Blog (http://blog.mila.com). Since over half a year, we get these notifications on top of our wordpress blog:

Notice: Undefined index: HTTP_HOST in /opt/wordpress/wp-includes/canonical.php on line 66
Notice: Undefined index: HTTP_HOST in /opt/wordpress/wp-includes/nav-menu-template.php on line 558

The notifications come and go, so i don't know what the problem is..
This is line 66 in the canonical file:

<?php
$requested_url .= $_SERVER['HTTP_HOST'];

And this is line 558 in nav-menu-template.php:

<?php
$current_url = set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_root_relative_current );

We know that the notification is shown because the variable HTTP_HOST is not set, but we don't know how to fix that. It would be great if you could help

Attachments (3)

canonical.php (24.9 KB) - added by theamila 9 years ago.
canonical.php file
nav-menu-template.php (24.5 KB) - added by theamila 9 years ago.
nav menu template file
34353.2.diff (1.4 KB) - added by oglekler 19 months ago.

Download all attachments as: .zip

Change History (71)

@theamila
9 years ago

canonical.php file

@theamila
9 years ago

nav menu template file

#1 @swissspidy
9 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

Duplicate of #32229. This is fixed in 4.4.

#2 @SergeyBiryukov
9 years ago

  • Focuses ui accessibility removed

#3 @theamila
9 years ago

  • Resolution duplicate deleted
  • Status changed from closed to reopened

I have inserted the lines from issue 32229 now i get this error:

Notice: Undefined index: host in /opt/wordpress/wp-includes/canonical.php on line 424
Notice: Undefined index: host in /opt/wordpress/wp-includes/canonical.php on line 425
Notice: Undefined index: host in /opt/wordpress/wp-includes/canonical.php on line 425
Notice: Undefined index: host in /opt/wordpress/wp-includes/canonical.php on line 426
Notice: Undefined index: host in /opt/wordpress/wp-includes/canonical.php on line 428
Notice: Undefined index: scheme in /opt/wordpress/wp-includes/canonical.php on line 445
Notice: Undefined index: host in /opt/wordpress/wp-includes/canonical.php on line 424
Notice: Undefined index: host in /opt/wordpress/wp-includes/canonical.php on line 425
Notice: Undefined index: host in /opt/wordpress/wp-includes/canonical.php on line 425
Notice: Undefined index: host in /opt/wordpress/wp-includes/canonical.php on line 426
Notice: Undefined index: host in /opt/wordpress/wp-includes/canonical.php on line 428
Notice: Undefined index: scheme in /opt/wordpress/wp-includes/canonical.php on line 445
Last edited 8 years ago by SergeyBiryukov (previous) (diff)

#4 @swissspidy
9 years ago

  • Keywords needs-patch added
  • Milestone set to Awaiting Review
  • Summary changed from Notifications on top of the page for canonical.php and nav-menu-template.php to redirect_canonical() – Undefined indexes 'host' and 'scheme'

Looks like $redirect['scheme'] and $original['host'] are not correctly set. Those two arrays are returned by parse_url, so it's certainly possible that those keys aren't set.

#5 @itproitserviceflcom
8 years ago

I have same warnings and found that it was produced by "HEAD" requests. "GET" and "POST" requests doesn't give the warning.

#6 @SergeyBiryukov
8 years ago

#39880 was marked as a duplicate.

#7 follow-up: @SergeyBiryukov
8 years ago

  • Milestone changed from Awaiting Review to 4.8

Related: #39827

This ticket was mentioned in Slack in #core by flixos90. View the logs.


8 years ago

#9 @flixos90
8 years ago

  • Milestone changed from 4.8 to Future Release

#10 @Andy Schmidt
7 years ago

This bug is still littering the log files in v4.9.4, out of the box. Spent time tracking down the cause and was going to report it, now realizing this is a known issue.

In my case, problem is that several times daily, redirect_canonical() is called with $_SERVER[HOST] empty and $_SERVER [URI] = '/'.

As a result $original[host] is never set and the code will eventually fail starting at lines 461 - 463:

<?php
        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'];

It should be trivial to fix at lines 70-73, currently:

<?php
        $original = @parse_url($requested_url);
        if ( false === $original ) {     // <-- this line requires a fix!
                return;
        }

by simply validating that a 'host' was actually set, since the code does expect one later:

<?php
        if ( false === $original or !isset( $original['host'] ) ) {
Last edited 7 years ago by Andy Schmidt (previous) (diff)

#11 in reply to: ↑ 7 @Andy Schmidt
7 years ago

  • Keywords has-patch added; needs-patch removed

I have confirmed that my proposed fix for 4.9.4 does address this problem. There was no recurrence in the past 4 days, and no ill effects!

Now that a confirmed fix is available, may I suggest moving it from some "future release" milestone to the next update, so that this may be closed after 2 years.

#12 @SergeyBiryukov
7 years ago

  • Milestone changed from Future Release to 5.0

#13 @archon810
7 years ago

While we're waiting for this fix, I'm also seeing a similar issue in wp-includes/class-wp-http-ixr-client.php.

ErrorException: Undefined index: host
#7 wp-includes/class-wp-http-ixr-client.php(27): handleError
#6 wp-includes/class-wp-http-ixr-client.php(27): __construct
#5 wp-includes/comment.php(2652): pingback
#4 wp-includes/comment.php(2486): do_all_pings
#3 wp-includes/class-wp-hook.php(286): apply_filters
#2 wp-includes/class-wp-hook.php(310): do_action
#1 wp-includes/plugin.php(515): do_action_ref_array
#0 wp-cron.php(126): null

Same for

Undefined index: scheme

Examining the $bits variable, I see this:

bits	
{
    path: /wordpress/xmlrpc.php
}

The function this happens in:

<?php
public function __construct($server, $path = false, $port = false, $timeout = 15) {
                if ( ! $path ) {
                        // Assume we have been given a URL instead
                        $bits = parse_url($server);
                        $this->scheme = $bits['scheme'];
                        $this->server = $bits['host'];
                        $this->port = isset($bits['port']) ? $bits['port'] : $port;
                        $this->path = !empty($bits['path']) ? $bits['path'] : '/';

All such errors are caused by wordpress/wp-cron.php?doing_wp_cron.

Perhaps the fix here can also be applied to class-wp-http-ixr-client.php?

Thank you.

#14 @RavanH
6 years ago

Not sure if this is completely related or just sounds very similar (involving path, not host or scheme) but I'll share it here as it may help in testing. I've encountered the following on a clean install of WP 4.9.8 with default theme and no plugins activated.

  1. Turn WP_DEBUG is on (obviously)
  2. Set permalinks to Numeric
  3. Visit a non-existent feed by it's plain URL, for example /?feed=sitemap

Notices shown:

PHP Notice:  Undefined index: path in /var/www/html/wp-includes/canonical.php on line 393
PHP Notice:  Undefined index: path in /var/www/html/wp-includes/canonical.php on line 393
PHP Notice:  Undefined index: path in /var/www/html/wp-includes/canonical.php on line 465

You may ask: Why bother with non-existent feeds? Answer: Plugin developers (as I) may add custom feed URLs and will encounter this notice during development (like I did) ... and waste a lot of time trying to find out what is going on ;)

#15 @SergeyBiryukov
6 years ago

  • Milestone changed from 5.0 to 5.1

#16 @SergeyBiryukov
6 years ago

#45254 was marked as a duplicate.

#17 @pento
6 years ago

  • Keywords needs-patch needs-unit-tests added; has-patch removed
  • Milestone changed from 5.1 to Future Release

This ticket needs a patch and tests.

#18 @Kovah
6 years ago

Unfortunately this is still an issue in WP 5.1.1 and currently littering our Sentry logs.

As of 5.1.1, line 504 of /wp/wp-includes/canonical.php is throwing the "Undefined index: host" error.
Corresponding code:

    // Ignore differences in host capitalization, as this can lead to infinite redirects
    // Only redirect no-www <=> yes-www
>>> 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'];
    }

#19 @robbiegod
6 years ago

FYI, I am running Wordpress 5.2, PHP 7.2. I am seeing this error display just below the body tag.

Notice: Undefined index: path in /wp-includes/canonical.php on line 419

#20 @JochenT
5 years ago

The reason for these notices are probably the same as I've found for multisites. See #47733 (Undefined index HTTP_HOST in wp-includes/ms-settings.php)

If this is true a more general handling of the HTTP server variables may be needed during the bootstrap/load process.

#21 @Cybr
5 years ago

This notice happens because HTTP/1.0 doesn't fill the HTTP_HOST index in $_SERVER. HTTP/1.1 and higher do support that index. Alas, around the world, archaic browsers and servers are still using HTTP/1.0.

Because of that, $requested_url isn't populated, and $original = @ parse_url( $requested_url ); won't have anything useful to parse, and won't fill in the host index. Ergo, three notices will pop up when trying to call $original['host'].

I think we can polyfill the $_SERVER['HTTP_HOST'] index early. Doing so would also address #47733. Be mindful of virtual hosts.

#22 @philraymond
4 years ago

5 years later, this still isn't fixed?

[09-Feb-2021 05:11:17 UTC] PHP Notice:  Undefined index: host in /home/hello/public_html/wp-includes/canonical.php on line 673
[09-Feb-2021 05:11:17 UTC] PHP Notice:  Undefined index: host in /home/hello/public_html/wp-includes/canonical.php on line 682
[09-Feb-2021 05:11:17 UTC] PHP Notice:  Undefined index: host in /home/hello/public_html/wp-includes/canonical.php on line 685
[09-Feb-2021 05:11:17 UTC] PHP Notice:  Undefined index: scheme in /home/hello/public_html/wp-includes/canonical.php on line 706
[09-Feb-2021 05:11:17 UTC] PHP Notice:  Undefined index: host in /home/hello/public_html/wp-includes/canonical.php on line 673
[09-Feb-2021 05:11:17 UTC] PHP Notice:  Undefined index: host in /home/hello/public_html/wp-includes/canonical.php on line 682
[09-Feb-2021 05:11:17 UTC] PHP Notice:  Undefined index: host in /home/hello/public_html/wp-includes/canonical.php on line 685
[09-Feb-2021 05:11:17 UTC] PHP Notice:  Undefined index: scheme in /home/hello/public_html/wp-includes/canonical.php on line 706
[09-Feb-2021 05:11:18 UTC] PHP Notice:  Undefined index: host in /home/hello/public_html/wp-includes/canonical.php on line 673
[09-Feb-2021 05:11:18 UTC] PHP Notice:  Undefined index: host in /home/hello/public_html/wp-includes/canonical.php on line 682
[09-Feb-2021 05:11:18 UTC] PHP Notice:  Undefined index: host in /home/hello/public_html/wp-includes/canonical.php on line 685
[09-Feb-2021 05:11:18 UTC] PHP Notice:  Undefined index: scheme in /home/hello/public_html/wp-includes/canonical.php on line 706
[09-Feb-2021 05:11:18 UTC] PHP Notice:  Undefined index: host in /home/hello/public_html/wp-includes/canonical.php on line 673
[09-Feb-2021 05:11:18 UTC] PHP Notice:  Undefined index: host in /home/hello/public_html/wp-includes/canonical.php on line 682
[09-Feb-2021 05:11:18 UTC] PHP Notice:  Undefined index: host in /home/hello/public_html/wp-includes/canonical.php on line 685
[09-Feb-2021 05:11:18 UTC] PHP Notice:  Undefined index: scheme in /home/hello/public_html/wp-includes/canonical.php on line 706
[09-Feb-2021 05:11:19 UTC] PHP Notice:  Undefined index: host in /home/hello/public_html/wp-includes/canonical.php on line 673
[09-Feb-2021 05:11:19 UTC] PHP Notice:  Undefined index: host in /home/hello/public_html/wp-includes/canonical.php on line 682
[09-Feb-2021 05:11:19 UTC] PHP Notice:  Undefined index: host in /home/hello/public_html/wp-includes/canonical.php on line 685
[09-Feb-2021 05:11:19 UTC] PHP Notice:  Undefined index: scheme in /home/hello/public_html/wp-includes/canonical.php on line 706
[09-Feb-2021 05:11:19 UTC] PHP Notice:  Undefined index: host in /home/hello/public_html/wp-includes/canonical.php on line 673
[09-Feb-2021 05:11:19 UTC] PHP Notice:  Undefined index: host in /home/hello/public_html/wp-includes/canonical.php on line 682
[09-Feb-2021 05:11:19 UTC] PHP Notice:  Undefined index: host in /home/hello/public_html/wp-includes/canonical.php on line 685
[09-Feb-2021 05:11:19 UTC] PHP Notice:  Undefined index: scheme in /home/hello/public_html/wp-includes/canonical.php on line 706

This ticket was mentioned in Slack in #core-test by hellofromtonya. View the logs.


4 years ago

#25 @mark8barnes
3 years ago

I'm experiencing a similar bug Undefined index: host in wp-includes/canonical.php:687.

#26 follow-up: @jojooba008
3 years ago

I'm also having the same problem.
My server is running on Ubuntu, and I found out that when bots etc. access 127.0.1.1 (not 127.0.0.1), I get the notice about canonical.php.
Could this information be a help in solving this problem?

#27 in reply to: ↑ 26 ; follow-up: @Andy Schmidt
3 years ago

Replying to jojooba008:

I'm also having the same problem.
My server is running on Ubuntu, and I found out that when bots etc. access 127.0.1.1 (not 127.0.0.1), I get the notice about canonical.php.
Could this information be a help in solving this problem?

Yes, this is indeed one of the circumstances known to trigger it.

What version of WordPress? The original problem was reported in Version 4 where it was not fixed for years, and now it won't be because of version 5.

If your problem still persists in version 5, that would be relevant.

#28 in reply to: ↑ 27 @jojooba008
3 years ago

Replying to Andy Schmidt:

Yes, this is indeed one of the circumstances known to trigger it.

What version of WordPress? The original problem was reported in Version 4 where it was not fixed for years, and now it won't be because of version 5.

If your problem still persists in version 5, that would be relevant.

Thanks Andy.
The version I'm using is 5.8.1 (the latest one).

#29 @mcjambi
3 years ago

My WordPress is a newest copy, Wordpress 5.8.2 and bug still there:

[11-Nov-2021 04:25:01 UTC] PHP Notice: Undefined index: scheme in /opt/bitnami/wordpress/wp-includes/canonical.php on line 720
[11-Nov-2021 10:32:14 UTC] PHP Notice: Undefined index: host in /opt/bitnami/wordpress/wp-includes/canonical.php on line 687
[11-Nov-2021 10:32:14 UTC] PHP Notice: Undefined index: host in /opt/bitnami/wordpress/wp-includes/canonical.php on line 696
[11-Nov-2021 10:32:14 UTC] PHP Notice: Undefined index: host in /opt/bitnami/wordpress/wp-includes/canonical.php on line 699

#30 @jorschot
3 years ago

changed line 66 to 71 to

if (( ! $requested_url && isset( $_SERVER['HTTP_HOST'] ) ) || $requested_url==0 ) {
                // Build the URL in the address bar.
                $requested_url  = is_ssl() ? 'https://' : 'http://';
                $requested_url .= $_SERVER['HTTP_HOST'];
                $requested_url .= $_SERVER['REQUEST_URI'];
        }

That worked for me

#31 @Mayhem30
3 years ago

I'm also having this issue :

[21-Dec-2021 11:27:10 UTC] PHP Warning:  Undefined array key "host" in /www/example.com/httpdocs/wp-includes/canonical.php on line 687
[21-Dec-2021 11:27:10 UTC] PHP Warning:  Undefined array key "host" in /www/example.com/httpdocs/wp-includes/canonical.php on line 696
[21-Dec-2021 11:27:10 UTC] PHP Warning:  Undefined array key "host" in /www/example.com/httpdocs/wp-includes/canonical.php on line 699
[21-Dec-2021 11:27:10 UTC] PHP Warning:  Undefined array key "scheme" in /www/example.com/httpdocs/wp-includes/canonical.php on line 720

#32 @stcn
3 years ago

Hi,

I'm also having this issue :

[16-Mar-2022 04:02:38 UTC] PHP Warning:  Undefined array key "host" in /public_html/wp-includes/canonical.php on line 687
[16-Mar-2022 04:02:38 UTC] PHP Warning:  Undefined array key "host" in /public_html/wp-includes/canonical.php on line 696
[16-Mar-2022 04:02:38 UTC] PHP Warning:  Undefined array key "scheme" in /public_html/wp-includes/canonical.php on line 720

what is the problem? how can it be solved?

Thanks!

#33 @ecomturbo
3 years ago

This bug is still littering the log files in v5.9.2, out of the box.
Seriously annoying. It would be really appreciated if this could be solved once and for all.
Thank you.

Undefined array key "host" unknown /wp-includes/canonical.php: 699
Undefined index: scheme unknown /wp-includes/canonical.php: 854
Undefined array key "host" unknown /wp-includes/canonical.php: 699
Undefined index: scheme unknown /wp-includes/canonical.php: 854

#34 @SergeyBiryukov
3 years ago

#55516 was marked as a duplicate.

#35 @yatgirl
3 years ago

so glad to have found this thread - I have been trying to track this error down forever. (thought it was just me) Cant believe the issue has been around 7 years and no resolution ?

[05-May-2022 19:53:53 UTC] PHP Notice:  Undefined index: host in /home/*removed*/public_html/wp-includes/canonical.php on line 687
[05-May-2022 19:53:53 UTC] PHP Notice:  Undefined index: host in /home/*removed*/public_html/wp-includes/canonical.php on line 696
[05-May-2022 19:53:53 UTC] PHP Notice:  Undefined index: host in /home/*removed*/public_html/wp-includes/canonical.php on line 699
[05-May-2022 19:53:53 UTC] PHP Notice:  Undefined index: scheme in /home/*removed*/public_html/wp-includes/canonical.php on line 720

This ticket was mentioned in PR #2687 on WordPress/wordpress-develop by RavanH.


3 years ago
#36

  • Keywords has-patch added; needs-patch removed

Filling in some blanks to fix some "Undefined index" notices.

Trac ticket: https://core.trac.wordpress.org/ticket/34353

#37 @ironprogrammer
2 years ago

  • Keywords needs-testing-info added

Not to cause unnecessary cross-talk, but for issue reproduction visibility between this and #39827:

For anyone still experiencing this issue, it would be most excellent if you would provide a list of test instructions and reproduction environment information on this ticket 🙌🏻 Please make sure to include any environment setup information that is necessary to reproduce the problem (e.g. a specific plugin or site configuration).

The debug.log output provided thus far is good to have, but please provide more detail so others may independently reproduce the problem, and validate any potential patches. Thanks!

#38 @Mayhem30
2 years ago

I'm not sure what these people are doing to create these errors, but here are the 2 offenders today.

Access log:

198.235.24.129 - [14/Jul/2022:19:49:15 -0700] GET / HTTP/1.1 "200" "-" "Expanse, a Palo Alto Networks company, searches across the global IPv4 space multiple times per day to identify customers&#39; presences on the Internet. If you would like to be excluded from our scans, please send IP addresses/domains to: scaninfo@paloaltonetworks.com"

109.248.6.15 - [15/Jul/2022:04:08:25 -0700] GET / HTTP/1.0 "200" "-" "masscan-ng/1.3 (https://github.com/bi-zone/masscan-ng)"

Error log :

[14-Jul-2022 02:49:29 UTC] PHP Warning:  Undefined array key "host" in /www/example.com/httpdocs/wp-includes/canonical.php on line 687
[14-Jul-2022 02:49:29 UTC] PHP Warning:  Undefined array key "host" in /www/example.com/httpdocs/wp-includes/canonical.php on line 696
[14-Jul-2022 02:49:29 UTC] PHP Warning:  Undefined array key "host" in /www/example.com/httpdocs/wp-includes/canonical.php on line 699
[14-Jul-2022 02:49:29 UTC] PHP Warning:  Undefined array key "scheme" in /www/example.com/httpdocs/wp-includes/canonical.php on line 720
[14-Jul-2022 02:49:29 UTC] PHP Warning:  Undefined array key "host" in /www/example.com/httpdocs/wp-includes/canonical.php on line 687
[14-Jul-2022 02:49:29 UTC] PHP Warning:  Undefined array key "host" in /www/example.com/httpdocs/wp-includes/canonical.php on line 696
[14-Jul-2022 02:49:29 UTC] PHP Warning:  Undefined array key "host" in /www/example.com/httpdocs/wp-includes/canonical.php on line 699
[14-Jul-2022 02:49:29 UTC] PHP Warning:  Undefined array key "scheme" in /www/example.com/httpdocs/wp-includes/canonical.php on line 720
[15-Jul-2022 11:08:25 UTC] PHP Warning:  Undefined array key "host" in /www/example.com/httpdocs/wp-includes/canonical.php on line 687
[15-Jul-2022 11:08:25 UTC] PHP Warning:  Undefined array key "host" in /www/example.com/httpdocs/wp-includes/canonical.php on line 696
[15-Jul-2022 11:08:25 UTC] PHP Warning:  Undefined array key "host" in /www/example.com/httpdocs/wp-includes/canonical.php on line 699
[15-Jul-2022 11:08:25 UTC] PHP Warning:  Undefined array key "scheme" in /www/example.com/httpdocs/wp-includes/canonical.php on line 720
[15-Jul-2022 11:08:25 UTC] PHP Warning:  Undefined array key "host" in /www/example.com/httpdocs/wp-includes/canonical.php on line 687
[15-Jul-2022 11:08:25 UTC] PHP Warning:  Undefined array key "host" in /www/example.com/httpdocs/wp-includes/canonical.php on line 696
[15-Jul-2022 11:08:25 UTC] PHP Warning:  Undefined array key "host" in /www/example.com/httpdocs/wp-includes/canonical.php on line 699
[15-Jul-2022 11:08:25 UTC] PHP Warning:  Undefined array key "scheme" in /www/example.com/httpdocs/wp-includes/canonical.php on line 720
Last edited 2 years ago by Mayhem30 (previous) (diff)

#39 follow-up: @ironprogrammer
2 years ago

In response to @Mayhem30:

Are you able to provide any specific details of the environment you're witnessing this in? Something along the lines of:

Environment Info

  • OS: macOS 12.4
  • Server: nginx/1.23.0
  • PHP: 7.4.30
  • WordPress: 6.0
  • Theme: twentytwentytwo v1.2
  • Active Plugins:
    • debug-bar v1.1.3
    • etc...

There might perhaps be some commonalities between environments where this is happening.

#40 follow-up: @yatgirl
2 years ago

I solved mine - the canonical errors no longer are appearing in my php error log. (see my post above for the canonical errors I was seeing constantly.)

I had an old plugin that is no longer being updated, but I want to keep it.
That old plugin was causing other php notice error lines in the php log. Since that old plugin will never be updated, I edited the file in that plugin and stopped it reporting the php notices (since it would never be fixed).

As soon as I stopped the php notice errors on that old plugin, the canonical php error notice errors also instantly stopped. So it appeared to me that these php canonical errors are reacting to other errors - In my case, I put a stop to the other errors and the canonical errors stop......

Last edited 2 years ago by yatgirl (previous) (diff)

#41 in reply to: ↑ 39 @Mayhem30
2 years ago

Replying to ironprogrammer:

In response to @Mayhem30:

Are you able to provide any specific details of the environment you're witnessing this in?
There might perhaps be some commonalities between environments where this is happening.

Yes, of course. Here is my info :

Environment

  • OS: FreeBSD 13.1-RELEASE
  • Web Server: Nginx 1.23.1
  • PHP: 8.0.20 (PHP-FPM)
  • WordPress: 6.01
  • Browser: Edge, Chrome, Firefox (latest versions)
  • Theme: Genesis Framework / Magazine Pro Theme
  • Active Plugins:
    • Classic Editor v1.6.2
    • Akismet Anti-Spam v4.2.5
    • Fast Secure Contact Form v4.0.56
    • Google XML Sitemaps v4.1.5
    • Subscribe to Comments Reloaded v220608
    • SyntaxHighlighter Evolved v3.6.2

With that said, I didn't realize the Fast Secure Contact Form was last updated 5 years ago. Also, this is what is shows when you go to the plugin page :

This plugin has been closed as of March 7th, 2019 and is not available for download. This closure is permanent. Reason: Guideline Violation.

I've disabled the plugin and will report back in a few days if that solved the issue.

Last edited 2 years ago by Mayhem30 (previous) (diff)

#42 in reply to: ↑ 40 ; follow-up: @RavanH
2 years ago

Replying to yatgirl:

As soon as I stopped the php notice errors on that old plugin, the canonical php error notice errors also instantly stopped. So it appeared to me that these php canonical errors are reacting to other errors - In my case, I put a stop to the other errors and the canonical errors stop......

How did you stop the notices? With the PHP function error_reporting() maybe? Please note that (depending on where you put the code) this will affect the error reporting level for everything that happens after that plugin loads, not just that particular plugin.

#43 follow-up: @Mayhem30
2 years ago

I found the issue and how to consistently reproduce the error.

$ curl --http1.0 -H 'User-Agent:' -H 'Accept:' -H 'Host:' https://example.com
[22-Jul-2022 02:00:40 UTC] PHP Warning:  Undefined array key "host" in /www/example.com/httpdocs/wp-includes/canonical.php on line 687
[22-Jul-2022 02:00:40 UTC] PHP Warning:  Undefined array key "host" in /www/example.com/httpdocs/wp-includes/canonical.php on line 696
[22-Jul-2022 02:00:40 UTC] PHP Warning:  Undefined array key "host" in /www/example.com/httpdocs/wp-includes/canonical.php on line 699
[22-Jul-2022 02:00:40 UTC] PHP Warning:  Undefined array key "scheme" in /www/example.com/httpdocs/wp-includes/canonical.php on line 720
[22-Jul-2022 02:00:40 UTC] PHP Warning:  Undefined array key "host" in /www/example.com/httpdocs/wp-includes/canonical.php on line 687
[22-Jul-2022 02:00:40 UTC] PHP Warning:  Undefined array key "host" in /www/example.com/httpdocs/wp-includes/canonical.php on line 696
[22-Jul-2022 02:00:40 UTC] PHP Warning:  Undefined array key "host" in /www/example.com/httpdocs/wp-includes/canonical.php on line 699
[22-Jul-2022 02:00:40 UTC] PHP Warning:  Undefined array key "scheme" in /www/example.com/httpdocs/wp-includes/canonical.php on line 720

I'm curious if anyone else with shell access have the same results?

Version 0, edited 2 years ago by Mayhem30 (next)

#44 in reply to: ↑ 43 @jojooba008
2 years ago

I tried running your script and got the error as well.
However, the message seems to be a little different from yours...?

[28-Jul-2022 09:53:59 UTC] PHP Notice:  Undefined index: host in /xxxxx/wp-includes/canonical.php on line 687
[28-Jul-2022 09:53:59 UTC] PHP Notice:  Undefined index: host in /xxxxx/wp-includes/canonical.php on line 696
[28-Jul-2022 09:53:59 UTC] PHP Notice:  Undefined index: host in /xxxxx/wp-includes/canonical.php on line 699

I also tried running it with "http1.0" as "http1.1" and this time no error appears.

Replying to Mayhem30:

I found the issue and how to consistently reproduce the error.

$ curl --http1.0 -H 'User-Agent:' -H 'Accept:' -H 'Host:' https://example.com
[22-Jul-2022 02:00:40 UTC] PHP Warning:  Undefined array key "host" in /www/example.com/httpdocs/wp-includes/canonical.php on line 687
[22-Jul-2022 02:00:40 UTC] PHP Warning:  Undefined array key "host" in /www/example.com/httpdocs/wp-includes/canonical.php on line 696
[22-Jul-2022 02:00:40 UTC] PHP Warning:  Undefined array key "host" in /www/example.com/httpdocs/wp-includes/canonical.php on line 699
[22-Jul-2022 02:00:40 UTC] PHP Warning:  Undefined array key "scheme" in /www/example.com/httpdocs/wp-includes/canonical.php on line 720
[22-Jul-2022 02:00:40 UTC] PHP Warning:  Undefined array key "host" in /www/example.com/httpdocs/wp-includes/canonical.php on line 687
[22-Jul-2022 02:00:40 UTC] PHP Warning:  Undefined array key "host" in /www/example.com/httpdocs/wp-includes/canonical.php on line 696
[22-Jul-2022 02:00:40 UTC] PHP Warning:  Undefined array key "host" in /www/example.com/httpdocs/wp-includes/canonical.php on line 699
[22-Jul-2022 02:00:40 UTC] PHP Warning:  Undefined array key "scheme" in /www/example.com/httpdocs/wp-includes/canonical.php on line 720

I'm curious if anyone else with shell access have the same results with their blog?

#45 @Mayhem30
2 years ago

For me, most of these errors are coming from bots that are using http 1.0 and not sending a host header.

I do see a few http 1.1 requests also triggering the error, but unable to find the cause of the issue.

#46 in reply to: ↑ 42 ; follow-up: @yatgirl
2 years ago

On just the main php page of the old abandoned plugin (visitor-maps.php), I put

error_reporting (E_ALL ^ E_NOTICE);

at the top of the page. Are you saying I did something wrong ? I thought this would affect just this plugin. Please let me know.

Replying to RavanH:

How did you stop the notices? With the PHP function error_reporting() maybe? Please note that (depending on where you put the code) this will affect the error reporting level for everything that happens after that plugin loads, not just that particular plugin.

Last edited 2 years ago by yatgirl (previous) (diff)

#47 in reply to: ↑ 46 ; follow-up: @RavanH
2 years ago

Replying to yatgirl:

On just the main php page of the old abandoned plugin (visitor-maps.php), I put

error_reporting (E_ALL ^ E_NOTICE);

at the top of the page. Are you saying I did something wrong ? I thought this would affect just this plugin. Please let me know.

No, not wrong :) That effectively will suppress all PHP notices, which in itself is not bad for a live site. It depends on how this visitor-maps.php file is used (is it the main plugin file or is it used as a front-end template?) whether your code will turn off notices for your complete site or only a particular public page. Still, not a problem unless you need notices for debugging...

#48 in reply to: ↑ 47 @yatgirl
2 years ago

Replying to RavanH:

Replying to yatgirl:

On just the main php page of the old abandoned plugin (visitor-maps.php), I put

error_reporting (E_ALL ^ E_NOTICE);

at the top of the page. Are you saying I did something wrong ? I thought this would affect just this plugin. Please let me know.

No, not wrong :) That effectively will suppress all PHP notices, which in itself is not bad for a live site. It depends on how this visitor-maps.php file is used (is it the main plugin file or is it used as a front-end template?) whether your code will turn off notices for your complete site or only a particular public page. Still, not a problem unless you need notices for debugging...


Thanks - the visitor maps is the admin main page of an admin report that shows who is on my site and what they are doing- it doesnt affect anything front end.
I guess doing that turned off all notices and I have found not having notices a breath of fresh air actually. They are just notices (which seems to be everyones attitude) and if the canonical one hasnt been rectified in 7 years, then I am glad to be rid of it. The constant notices in my log just take away from the warnings etc that are important.

#49 @bcolflesh
23 months ago

This still happens in 6.1.1 -

2023/01/16 21:41:33 [error] 1166#1166: *222553 FastCGI sent in stderr: "PHP message: PHP Notice: Undefined index: host in /my/path/wp-includes/canonical.php on line 689PHP message: PHP Notice: Undefined index: host in /my/path/wp-includes/canonical.php on line 698PHP message: PHP Notice: Undefined index: host in /my/path/wp-includes/canonical.php on line 701" while reading response header from upstream, client: 99.99.100.99, server: 99.99.99.100, request: "GET / HTTP/1.0", upstream: "fastcgi://unix:/var/run/php/php7.4-fpm.sock:"

Why not update the handler for cases when host is not set?

#50 @costdev
22 months ago

#57684 was marked as a duplicate.

#51 @ironprogrammer
19 months ago

#58162 was marked as a duplicate.

This ticket was mentioned in PR #4432 on WordPress/wordpress-develop by @oglekler.


19 months ago
#52

In the absence of $_SERVER['HTTP_HOST'] while http1.0 protocol is used, the only available way to go through all other checks is to assume that the host and port are already correct and take them from the site settings.

Trac ticket: #34353

@oglekler
19 months ago

#53 @Mayhem30
19 months ago

@oglekler Thank you, this patch solved the issue for me.

@oglekler commented on PR #4432:


19 months ago
#54

@costdev Thank you for correcting me. I will make tests, I just need a bit of a time for this )

#55 follow-up: @nestormarius
18 months ago

I've also applied the diff from @oglekler and now my error_log file only outputs this warning.

Undefined array key "path" in /home/xxx/public_html/wp-includes/canonical.php on line 710

Line 710 shows

$compare_original = array( $original['host'], $original['path'] );

Later edit: I forgot to mention that in the original canonical.php file line 710 is actually line 701, so it won't confuse anyone.

Any idea how to fix it?
Thanks!

Later edit: I reverted the changes as the diff breaks things in my Wordpress site.

Last edited 18 months ago by nestormarius (previous) (diff)

#56 @Slams
17 months ago

After enabling the HTTP/3.0 protocol, I'm receiving such warnings:

Undefined array key "host" in /wp-includes/canonical.php on line 699
Undefined array key "scheme" in /wp-includes/canonical.php on line 720
Undefined array key "host" in /wp-includes/canonical.php on line 687
Undefined array key "host" in /wp-includes/canonical.php on line 696

Didn't test @oglekler patch yet.

P.S. Warnings disappeared after patch.

Last edited 17 months ago by Slams (previous) (diff)

#57 in reply to: ↑ 55 @fibrojedi
17 months ago

Replying to nestormarius:

I've also applied the diff from @oglekler and now my error_log file only outputs this warning.

Undefined array key "path" in /home/xxx/public_html/wp-includes/canonical.php on line 710

Line 710 shows

$compare_original = array( $original['host'], $original['path'] );

Later edit: I forgot to mention that in the original canonical.php file line 710 is actually line 701, so it won't confuse anyone.

Any idea how to fix it?
Thanks!

Later edit: I reverted the changes as the diff breaks things in my WordPress site.

I also just tried the patch and the errors are

[12-Jul-2023 11:18:56 UTC] PHP Warning:  Undefined array key "host" in /mnt/1c88b8d1-c48e-4b2e-92b3-89e869e10559/xxx/wp-includes/canonical.php on line 706
[12-Jul-2023 11:18:56 UTC] PHP Warning:  Undefined array key "host" in /mnt/1c88b8d1-c48e-4b2e-92b3-89e869e10559/xxx/wp-includes/canonical.php on line 715

Those lines in canonical.php are

 706: $original_host_low = strtolower( $original['host'] );
 715: $redirect['host'] = $original['host'];

I'm on PHP8.2 in case it helps anyone. It seems $redirect['host'] doesn't trigger it (as line 707 isn't flagged as containing an error, but $original['host'] does trip the error.

I'm happy to test anything as these warnings fill up my error logs, but I don't want to suppress warnings either.

Thanks.

Last edited 17 months ago by fibrojedi (previous) (diff)

#58 @fibrojedi
17 months ago

As an addendum (if that's allowed?) - another user said deactivating a plugin fixed it for them. I deactivated all plugins and reverted to a standard theme, but the errors still persisted.

I'm on 6.2.2.

Extra Note: on my local version (not public), I'm on the 6.2.3-alpha-55925 and this error is not currently occurring for me. I'm too much of a wuss to try this on my live site, but it may be that this issue is fixed now (or will be when this hits general release).

#59 @SergeyBiryukov
16 months ago

#59146 was marked as a duplicate.

svaningelgem commented on PR #4432:


5 months ago
#60

Hi @OlaIola , did you have time to add the tests for this? I came here because these notices keep popping up on my WP site.

#61 @jpswade
5 months ago

Wordpress Version 6.6.1
PHP version 8.3.9

FastCGI sent in stderr: "PHP message: PHP Warning:  Undefined array key "host" in /var/www/html/wp-includes/canonical.php on line 716; PHP message: PHP Warning:  Undefined array key "host" in /var/www/html/wp-includes/canonical.php on line 727; PHP message: PHP Warning:  Undefined array key "host" in /var/www/html/wp-includes/canonical.php on line 730" while reading response header from upstream, client: 205.210.31.140, server: _, request: "GET / HTTP/1.0", upstream: "fastcgi://unix:/var/run/php/php8.3-fpm.sock:"

#62 @Sceko
4 months ago

Same for me did anyone fix?

#63 @Mayhem30
4 months ago

I solved the issue by adding the following to my php-fpm.conf file :

fastcgi_param HOST  $server_name;
fastcgi_param HTTP_HOST  $server_name;

It seems you need to send both HOST and HTTP_HOST params.

#64 @Mte90
3 months ago

I am here with the same issue:

[10-Sep-2024 16:05:12 UTC] PHP Notice:  Undefined index: host in /var/www/wp-includes/canonical.php on line 716
[10-Sep-2024 16:05:12 UTC] PHP Notice:  Undefined index: host in /var/www/wp-includes/canonical.php on line 727
[10-Sep-2024 16:05:12 UTC] PHP Notice:  Undefined index: host in /var/www/wp-includes/canonical.php on line 730
[10-Sep-2024 16:05:12 UTC] PHP Notice:  Undefined index: scheme in /var/www/wp-includes/canonical.php on line 751
[10-Sep-2024 16:05:12 UTC] PHP Notice:  Undefined index: host in /var/www/wp-includes/canonical.php on line 716
[10-Sep-2024 16:05:12 UTC] PHP Notice:  Undefined index: host in /var/www/wp-includes/canonical.php on line 727
[10-Sep-2024 16:05:12 UTC] PHP Notice:  Undefined index: host in /var/www/wp-includes/canonical.php on line 730
[10-Sep-2024 16:05:12 UTC] PHP Notice:  Undefined index: scheme in /var/www/wp-includes/canonical.php on line 751

#65 @ironprogrammer
4 weeks ago

#62362 was marked as a duplicate.

#66 @ironprogrammer
4 weeks ago

#62245 was marked as a duplicate.

#67 @ironprogrammer
4 weeks ago

#60173 was marked as a duplicate.

#68 @ironprogrammer
3 weeks ago

#62334 was marked as a duplicate.

Note: See TracTickets for help on using tickets.