WordPress real IP address fix

WordPress could be behind reverse proxy and $_SERVER['REMOTE_ADDR'] variable could show wrong IP address.
Add this code to wp-config.php to fix wrong IP:

if ( !empty( $_SERVER['HTTP_CLIENT_IP'] ) ) { //check ip from share internet
} elseif ( !empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) { // to check ip is pass from proxy, also could be used ['HTTP_X_REAL_IP ']
} else {

$_SERVER['REMOTE_ADDR'] = $ip; // set ip via complex method because remote_addr could have proxy ip

Article about getting real IP address.

Leave a Comment