Merge pull request #7355 from woothemes/better-ip-check

Better proxy server support for get_ip_address
This commit is contained in:
Mike Jolley 2015-02-11 10:41:44 +00:00
commit 124dac4a24
1 changed files with 10 additions and 1 deletions

View File

@ -54,7 +54,16 @@ class WC_Geolocation {
* @return string * @return string
*/ */
public static function get_ip_address() { public static function get_ip_address() {
return isset( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : isset( $_SERVER['REMOTE_ADDR'] ) ? $_SERVER['REMOTE_ADDR'] : ''; if ( isset( $_SERVER['X-Real-IP'] ) ) {
return $_SERVER['X-Real-IP'];
} elseif ( isset( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) {
// Proxy servers can send through this header like this: X-Forwarded-For: client1, proxy1, proxy2
// Make sure we always only send through the first IP in the list which should always be the client IP.
return trim( current( explode( ',', $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) );
} elseif ( isset( $_SERVER['REMOTE_ADDR'] ) ) {
return $_SERVER['REMOTE_ADDR'];
}
return '';
} }
/** /**