Title: _remote_ip problems
Last modified: March 22, 2018

---

# _remote_ip problems

 *  Resolved [Eric](https://wordpress.org/support/users/winmkt/)
 * (@winmkt)
 * [8 years ago](https://wordpress.org/support/topic/_remote_ip-problems/)
 * 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](https://wordpress.org/plugins/wp-mail-smtp/) plugin
    - Using [Breeze](https://wordpress.org/plugins/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](https://wordpress.org/support/users/winmkt/).

Viewing 1 replies (of 1 total)

 *  Thread Starter [Eric](https://wordpress.org/support/users/winmkt/)
 * (@winmkt)
 * [8 years ago](https://wordpress.org/support/topic/_remote_ip-problems/#post-10104750)
 * 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](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.

 * ![](https://ps.w.org/contact-form-7/assets/icon.svg?rev=2339255)
 * [Contact Form 7](https://wordpress.org/plugins/contact-form-7/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/contact-form-7/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/contact-form-7/)
 * [Active Topics](https://wordpress.org/support/plugin/contact-form-7/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/contact-form-7/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/contact-form-7/reviews/)

## Tags

 * [IP](https://wordpress.org/support/topic-tag/ip/)
 * [remote ip](https://wordpress.org/support/topic-tag/remote-ip/)

 * 1 reply
 * 1 participant
 * Last reply from: [Eric](https://wordpress.org/support/users/winmkt/)
 * Last activity: [8 years ago](https://wordpress.org/support/topic/_remote_ip-problems/#post-10104750)
 * Status: resolved