Betterer IP address detection. #449
Conversation
There is also a filter that can be used to customize the lookup order and/or add/remove sources that are searched when looking for the current IP address. From the ZenCache source code we find this: $sources = array(
'HTTP_CF_CONNECTING_IP',
'HTTP_CLIENT_IP',
'HTTP_X_FORWARDED_FOR',
'HTTP_X_FORWARDED',
'HTTP_X_CLUSTER_CLIENT_IP',
'HTTP_FORWARDED_FOR',
'HTTP_FORWARDED',
'HTTP_VIA',
'REMOTE_ADDR',
);
$sources = $this->apply_filters(__METHOD__.'_sources', $sources); So to modify the list of sources create this directory and file:
<?php
add_filter('zencache\\share::current_ip_sources', function($sources)
{
// A source is an array key in the `$_SERVER` superglobal.
return array(
'HTTP_CF_CONNECTING_IP',
'HTTP_CLIENT_IP',
'HTTP_X_FORWARDED_FOR',
'HTTP_X_FORWARDED',
'HTTP_X_CLUSTER_CLIENT_IP',
'HTTP_FORWARDED_FOR',
'HTTP_FORWARDED',
'HTTP_VIA',
'REMOTE_ADDR',
);
}); |
Merged. Thank you! |
@jaswsinc What is the old behavior?
Thank you! I'll create a KB Article to document this. |
Old BehaviorTo use New Behavior w/ Filter to RevertThe filter I provided above will not replicate that exactly, but it is very very close. <?php
add_filter('zencache\\share::current_ip_prioritize_remote_addr', '__return_true'); With this filter in place, if However, if |
@jaswsinc Perfect. Thanks for explaining that! I document that in a KB Article. |
Next release changelog:
|
@jaswsinc I wrote a KB Article to document your notes above. Thanks for explaining so clearly! :-) http://zencache.com/kb-article/how-do-i-customize-ip-address-detection/ |
@raamdev writes...
Cool! Great :-) |
Improves IP address detection.
Supports CloudFlare IP forwarding.
Supports multiple IPs in a single header.
The following lookup order is used by ZenCache. We use the first public IP address found in these headers, starting from the top and working down.
Supports a filter in case a site owner would like to revert to the old behavior.
Create this directory and file:
/wp-content/mu-plugins/zc-prioritize-remote-addr.php