Viewing 3 replies - 1 through 3 (of 3 total)
  • Hey; so if you were to try and get the IP via $_SERVER['REMOTE_ADDR'] you would instead reach CloudFlare’s servers. So there are two ways around this.

    The first is to modify your PHP to look something like this:

    if (isset($_SERVER["HTTP_CF_CONNECTING_IP"])) {
        $ip = $_SERVER["HTTP_CF_CONNECTING_IP"];
    } else {
        $ip = $_SERVER["REMOTE_ADDR"];
    }

    Then use that IP variable however you please.

    The other way is to use Mod_CloudFlare on Apache, or modify your Nginx configuration.

    Let me know if you need anything else.

    Junade (Community Manager @ CloudFlare)

    Thread Starter hugooodias

    (@hugooodias)

    Hey, icyapril thanks for answering.

    I’ve actually updated the plugin code with something like that, but instead I have used the HTTP_X_FORWARDED_FOR for solving this issue. It worked!

    I know, isn’t the best practice to modify the plugin but, in this case, was essential.

    Hey;

    Just a heads up – the HTTP-X-Forwarded-For header can be overwritten later down the chain; so it can have the IP of an internal relay instead of a CF header; also it can even be a comma separated list.

    Thanks

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Visitor IP address not working when using varnish & Cloudflare’ is closed to new replies.