Convert array keys for $_SERVER to uppercase

It seems to be the case, that array indicies in $_SERVER are always
uppercase. Sadly I could not find any documentation of this but at
least with mod_php it is the case. Also a extensive search on github
projects seems to support this thesis.

On my installation the 'X-FORWARDED-PROTO' is even then uppercase when
its mixed case in the Header provided by the reverse proxy.

Signed-off-by: Jan Losinski <losinski@wh2.tu-dresden.de>
This commit is contained in:
Jan Losinski 2017-04-13 02:26:32 +02:00
parent 8313f765ce
commit e97c9674e9
2 changed files with 16 additions and 16 deletions

View File

@ -184,20 +184,20 @@ ob_end_clean();
* Override server-detected variables with those from X-Forwarded headers * Override server-detected variables with those from X-Forwarded headers
*/ */
if ( isset($c->trust_x_forwarded) && $c->trust_x_forwarded ) { if ( isset($c->trust_x_forwarded) && $c->trust_x_forwarded ) {
if ( isset($_SERVER['X-Real-IP']) ) { if ( isset($_SERVER['HTTP_X_REAL_IP']) ) {
$_SERVER['REMOTE_ADDR'] = $_SERVER['X-Real-IP']; $_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_X_REAL_IP'];
} elseif ( isset($_SERVER['X-Forwarded-For']) ) { } elseif ( isset($_SERVER['HTTP_X_FORWARDED_FOR']) ) {
list($_SERVER['REMOTE_ADDR'], $rest) = explode( ',', $_SERVER['X-Forwarded-For']); list($_SERVER['REMOTE_ADDR'], $rest) = explode( ',', $_SERVER['HTTP_X_FORWARDED_FOR']);
} }
if ( isset($_SERVER['X-Forwarded-Proto']) ) { if ( isset($_SERVER['HTTP_X_FORWARDED_PROTO']) ) {
if ($_SERVER['X-Forwarded-Proto'] == 'https') { if ($_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') {
$_SERVER['HTTPS'] = 'on'; $_SERVER['HTTPS'] = 'on';
} else { } else {
$_SERVER['HTTPS'] = 'off'; $_SERVER['HTTPS'] = 'off';
} }
} }
if ( isset($_SERVER['X-Forwarded-Port']) ) { if ( isset($_SERVER['HTTP_X_FORWARDED_PORT']) ) {
$_SERVER['SERVER_PORT'] = $_SERVER['X-Forwarded-Port']; $_SERVER['SERVER_PORT'] = $_SERVER['HTTP_X_FORWARDED_PORT'];
} }
} }

View File

@ -184,20 +184,20 @@ ob_end_clean();
* Override server-detected variables with those from X-Forwarded headers * Override server-detected variables with those from X-Forwarded headers
*/ */
if ( isset($c->trust_x_forwarded) && $c->trust_x_forwarded ) { if ( isset($c->trust_x_forwarded) && $c->trust_x_forwarded ) {
if ( isset($_SERVER['X-Real-IP']) ) { if ( isset($_SERVER['HTTP_X_REAL_IP']) ) {
$_SERVER['REMOTE_ADDR'] = $_SERVER['X-Real-IP']; $_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_X_REAL_IP'];
} elseif ( isset($_SERVER['X-Forwarded-For']) ) { } elseif ( isset($_SERVER['HTTP_X_FORWARDED_FOR']) ) {
list($_SERVER['REMOTE_ADDR'], $rest) = explode( ',', $_SERVER['X-Forwarded-For']); list($_SERVER['REMOTE_ADDR'], $rest) = explode( ',', $_SERVER['HTTP_X_FORWARDED_FOR']);
} }
if ( isset($_SERVER['X-Forwarded-Proto']) ) { if ( isset($_SERVER['HTTP_X_FORWARDED_PROTO']) ) {
if ($_SERVER['X-Forwarded-Proto'] == 'https') { if ($_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') {
$_SERVER['HTTPS'] = 'on'; $_SERVER['HTTPS'] = 'on';
} else { } else {
$_SERVER['HTTPS'] = 'off'; $_SERVER['HTTPS'] = 'off';
} }
} }
if ( isset($_SERVER['X-Forwarded-Port']) ) { if ( isset($_SERVER['HTTP_X_FORWARDED_PORT']) ) {
$_SERVER['SERVER_PORT'] = $_SERVER['X-Forwarded-Port']; $_SERVER['SERVER_PORT'] = $_SERVER['HTTP_X_FORWARDED_PORT'];
} }
} }