Skip to content

Commit

Permalink
Account for multiple IPs in the forwarded header
Browse files Browse the repository at this point in the history
  • Loading branch information
kasparsd committed Oct 16, 2023
1 parent e4ac85c commit 648e381
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,19 @@ If `$_SERVER['REMOTE_ADDR']` is not configured, the plugin will attempt to extra
Update your server configuration to set the `$_SERVER['REMOTE_ADDR']` variable to the verified client IP address or use the `wp_stream_client_ip_address` filter to do that:

`add_filter(
'wp_stream_client_ip_address',
function( $client_ip ) {
// Trust the X-Forwarded-For header.
if ( ! empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) {
return $_SERVER['HTTP_X_FORWARDED_FOR'];
}

return $client_ip;
}
'wp_stream_client_ip_address',
function( $client_ip ) {
// Trust the first IP in the X-Forwarded-For header.
if ( ! empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) {
$forwarded_ips = explode( ',' $_SERVER['HTTP_X_FORWARDED_FOR'] );

if ( filter_var( $forwarded_ips[0], FILTER_VALIDATE_IP ) ) {
return $forwarded_ips[0];
}
}

return $client_ip;
}
);`


Expand Down

0 comments on commit 648e381

Please sign in to comment.