How to get visitor IP address over Cloudflare

Because Cloudflare acts as a proxy, you will notice changes to the way that your website visitors’ IP addresses are displayed both in your server logs and WordPress – notably that all access appears to be coming from Cloudflare IP addresses. 

To fix this problem add the following snippet to your WordPress wp-config.php file.

// Add Code To WP-Config.php

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

– LAST TESTED DECEMBER 9, 2019

Code not working? Let us know in the comments below.

Latest Snippets

Leave a comment