WordPress Comment Author IP Address Showing Wrong [Fixed]

Recently, I noticed on our blog post comments. I saw something is going wrong with the comment system of WordPress, the comment author’s IP address was wrong.

Incorrect WordPress Comment Author IP

I researched Google and find out in some technical cases WordPress also shows the localhost IP (127.0.0.1) address. If your WordPress website is showing, incorrect or localhost IP addresses of the comment author, then this article will help you to fix this problem. There are two cases, to show incorrect and localhost IP addresses of the comment author.

First, it depends on the server configuration. If you are using varnish on a WordPress site then it is normal to show a local IP address instead of the client’s real IP.

In the second case, If you are using Cloudflare CDN for performance or Ezoic ad-network to monetize the website, then WordPress shows incorrect IP addresses of the comment author. It shows the CDN’s IP address instead of the client’s real IP address.

Fix Locahost IP Address of Comment Author in WordPress

Note: Before proceeding with the steps, we recommend taking a complete backup of your site. Anything goes wrong, you can restore it anytime.

Step – 1. Connect to your server using FTP/SFTP/SSH

Step – 2. Go to public_html or the WordPress installation directory

Step – 3. Edit wp-config.php

Step – 4. Add these lines of code before /* That’s all, stop editing! Happy blogging. */

/** Code for showing correct IP address of comment author */ 
if(isset($_SERVER['HTTP_X_FORWARDED_FOR'])) { 
$xffaddrs = explode(',',$_SERVER['HTTP_X_FORWARDED_FOR']); 
$_SERVER['REMOTE_ADDR'] = $xffaddrs[0]; 
}
Adding Code in wp-config.php file

Step – 5. Save Changes.

Fix Incorrect IP Address while Using Cloudflare or Ezoic CDN

As I have mentioned above and noticed that the comments author’s IP was showing incorrect. I checked the location of these IP addresses using the KeyCDN IP locator, and the result was different but the IP’s service provider was the same.

Must read: How to Imagick Missing Module on WordPress

On my site, I am using Ezoic ad-network and Ezoic uses CDN networks, so when visitors comment on the content it shows the CDN’s IP address instead of real IP, if you are using Cloudflare, the problems will be the same.

So, here are some lines of codes, for fixing the incorrect IP address for the WordPress comment author. You must add in the wp-config.php file, in the same procedure as mentioned above.

/* Show Correct IP in case of Cloudflare or Ezoic */
if(array_key_exists('HTTP_CF_CONNECTING_IP', $_SERVER)){ 
	$_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_CF_CONNECTING_IP']; 
   }
Show Correct IP Cloudflare in case of Cloudflare or Ezoic

Show Correct IP Address of Coment Author Using Plugin

There are some plugins, you can use one of them to show correct IP address of comment author or visitors. Plugin like Real Proxy IP and Real IP Detector use the same method, that we have mentioned above.

Particulary I found another plugin Real IP and Geo for Cloudflare, this plugin shows geo location with client’s real IP and the Cloudflare proxy IP.

Real IP and Geo for Cloudflare

If you use this plugin, it show more details compared to others, even from the custom code methods. But this plugin has a negative point in my opinion, this plugin don’t store the records on database, means if you uninstalled the plugin it will remove the geo and client’s real IP address. But other hand if you use Real Proxy IP or Real IP Detector, it will store the IP address on the database.

Conclusion

Using Cloudflare CDN or any CDN services for your WordPress website, then you might have this IP related issue. If you have monetized your website with Ezoic ad-network, then you will also facing the same issue.

When you use these services, clients IP addresses not forwarded to WordPress properly and shows the proxy IP addresses, and that is technically incorrect.

So, using any of the method you can fix the IP issue on WordPress, and if you are still facing the issue, then don’t forget to comment.


Please Support

If you like our content, please consider buying us a coffee.
Thank you for your support!

Pronay Sarkar

Hello!
I am Pronay Sarkar, I love to write about tech and stuff. I am a college graduate from the University of Delhi.

2 thoughts on “WordPress Comment Author IP Address Showing Wrong [Fixed]”

    • Thank you Shubham Bhai for the comment. Using CDN or any proxy servers on the Website is helpful for protection and performance but, lack of proper configuration WordPress can’t detect the real IP address.

      Reply

Leave a Comment