Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
WordPress Config: Use X-Forwarded-For HTTP Header to Get Visitor's Real IP Address
// Use X-Forwarded-For HTTP Header to Get Visitor's Real IP Address
if ( isset( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) {
$http_x_headers = explode( ',', $_SERVER['HTTP_X_FORWARDED_FOR'] );
$_SERVER['REMOTE_ADDR'] = $http_x_headers[0];
}
@fbitti

This comment has been minimized.

Copy link

@fbitti fbitti commented Jun 15, 2017

Thanks for this tip. It's exactly what I was looking for, Ryan.
Any chance this option will become available as a plugin, so regular Wordpress users don't have to touch the code?
@luisan00, mira esto :)

@iamkingsleyf

This comment has been minimized.

Copy link

@iamkingsleyf iamkingsleyf commented Jul 15, 2017

Thanks

@taropaa

This comment has been minimized.

Copy link

@taropaa taropaa commented Feb 7, 2019

Works perfectly with Cloudflare! Thank you

@pbraconnot

This comment has been minimized.

Copy link

@pbraconnot pbraconnot commented Mar 23, 2020

Thanks. Working with Ithemes Security plugin behind proxy.

@fabswt

This comment has been minimized.

Copy link

@fabswt fabswt commented Apr 23, 2020

For anyone hosting their WordPress blog on Heroku: the left-most IP is not guaranteed to be the client's real IP, while the right-most one should be, as per this answer .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.