WordPress.org

Make WordPress Core

Ticket #9235: 9235.2.diff

File 9235.2.diff, 1.8 KB (added by Denis-de-Bernardy, 9 years ago)
  • wp-settings.php

     
    105105if ( empty($PHP_SELF) )
    106106        $_SERVER['PHP_SELF'] = $PHP_SELF = preg_replace("/(\?.*)?$/",'',$_SERVER["REQUEST_URI"]);
    107107
     108// Correct comment's ip address with X-Forwarded-For http header if you are behind a proxy or load balancer.
     109if ( isset($_SERVER['HTTP_X_FORWARDED_FOR']) ) {
     110        // this one can have multiple IPs separated by a coma
     111        $_SERVER['HTTP_X_FORWARDED_FOR'] = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
     112        $_SERVER['HTTP_X_FORWARDED_FOR'] = $_SERVER['HTTP_X_FORWARDED_FOR'][0];
     113}
     114
     115if ( function_exists('filter_var') ) {
     116        if ( isset($_SERVER['HTTP_X_FORWARDED_FOR']) && filter_var($_SERVER['HTTP_X_FORWARDED_FOR'], FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE) )
     117                $_SERVER['REMOTE_ADDR'] = filter_var($_SERVER['HTTP_X_FORWARDED_FOR'], FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE);
     118        elseif ( isset($_SERVER['HTTP_X_REAL_IP']) && filter_var($_SERVER['HTTP_X_REAL_IP'], FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE) )
     119                $_SERVER['REMOTE_ADDR'] = filter_var($_SERVER['HTTP_X_REAL_IP'], FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE);
     120} else {
     121        if ( isset($_SERVER['HTTP_X_FORWARDED_FOR']) )
     122                $_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_X_FORWARDED_FOR'];
     123        elseif ( isset($_SERVER['HTTP_X_REAL_IP']) )
     124                $_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_X_REAL_IP'];
     125}
     126
     127
    108128if ( version_compare( '4.3', phpversion(), '>' ) ) {
    109129        die( sprintf( /*WP_I18N_OLD_PHP*/'Your server is running PHP version %s but WordPress requires at least 4.3.'/*/WP_I18N_OLD_PHP*/, phpversion() ) );
    110130}
     
    683703// Everything is loaded and initialized.
    684704do_action('init');
    685705
    686 ?>
     706?>
     707 No newline at end of file