Advanced-administration-handbook icon indicating copy to clipboard operation
Advanced-administration-handbook copied to clipboard

SSL on reverse proxy code example update

Open ethanclevenger91 opened this issue 1 year ago • 4 comments

Issue Description

The code example currently on this page will throw PHP notices when running WP-CLI commands, potentially in other situations in which wp-config.php is loaded outside the context of a normal web request, or when the request is missing expected headers.

URL of the Page with the Issue

https://wordpress.org/support/article/administration-over-ssl/

Section of Page with the issue

The Reverse Proxy example

Why is this a problem?

PHP notices are noisy.

Suggested Fix

if (strpos($_SERVER['HTTP_X_FORWARDED_PROTO'], 'https') !== false)
$_SERVER['HTTPS']='on';

Should become...

if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && strpos($_SERVER['HTTP_X_FORWARDED_PROTO'], 'https') !== false)
$_SERVER['HTTPS']='on';

Personally, I'd also add curly braces, but I would ultimately defer that decision to core's code style guide. Not sure what the policy is without looking.

ethanclevenger91 avatar Oct 21 '22 21:10 ethanclevenger91