• Resolved Eric

    (@winmkt)


    I moved a website to a new hosting service and _remote_ip started not working properly. It started reporting 127.0.0.1 as the IP for all form submissions.

    The hosting company asked me to add the following to my wp-config.php file and it fixes the problem only if I disable Varnish cache.

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

    Once I enable Varnish with the above code in wp-config.php, I get nothing for _remote_ip (without above code, I get 127.0.0.1).

    Disabling Varnish is not a good option so I’m looking for another solution.

    Additional info that might be relevant:

    • Host is Cloudways with DigitalOcean server
    • Using Mailgun for SMTP
    • Using WP Mail SMTP plugin
    • Using Breeze cache plugin
    • Using Cloudflare

    Any ideas for getting _remote_ip to report the proper IP address?

    Eric

    • This topic was modified 8 years ago by Eric.
Viewing 1 replies (of 1 total)
  • Thread Starter Eric

    (@winmkt)

    While waiting for help, I continued searching and found a fix for my problem. By the look of what I found, I guess that remote_ip doesn’t work properly with Cloudflare.

    There is a code snippet very similar to the code in my prior message that was provided by my hosting company that fixed the problem. The variation that should have been added to wp-config.php is below. I included the comments from the person who provided the snippet which briefly explains the code. This was found at: https://gist.github.com/vhsu/aad62aafd2f782e826f8c0e3589b5440

    // Override $_SERVER['REMOTE_ADDR'] on WordPress to retrieve the client ip for cloudflare users
    // This will also correct the [_remote_ip] shortcode with contact form 7 ( wpcf7 ) or any other plugin using $_SERVER['REMOTE_ADDR']
    // Simply add the following code in the wp_config.php file and you're done.
    if (isset($_SERVER["HTTP_CF_CONNECTING_IP"])) {
      $_SERVER['REMOTE_ADDR'] = $_SERVER["HTTP_CF_CONNECTING_IP"];
    }

    Eric

Viewing 1 replies (of 1 total)

The topic ‘_remote_ip problems’ is closed to new replies.