Fix WordPress error displaying the IP address of Localhost


Depending on the software that you install on your server and how it is configured, the client IP address may not be forwarded properly. Unfortunately, WordPress doesn’t include the option to forward client IP addresses. Taimienphi.vn article will guide you how to fix WordPress error displaying Localhost’s IP address in user comments.


On a regular web server, WordPress does not have any problems related to displaying the correct IP address of site visitors or commenters, etc.

However on some other servers, WordPress may not display the correct IP address in the comments panel or other locations. Instead, WordPress displays the IP address of Localhost as 127.0.0.1. Therefore, this article will guide you how to fix WordPress errors showing the IP address of Localhost on user comments.

Fix incorrect IP address on WordPress

Note: Before editing any file in WordPress, you should create a backup file to avoid possible bad situations.

The easiest way to solve this problem is to add a code snippet to the file “wp-config.php“To do this, open the FTP client, then log in to your FTP account and open the file wp-config.php.

fix wordpress error, display local ip address of localhost 2

After opening the file, copy the code snippet below into the paste at the bottom of the file:

// Code for showing correct client IP address

if (isset ($ _SERVER[‘HTTP_X_FORWARDED_FOR’] )) {

$ mte_xffaddrs = explode (‘,’, $ _SERVER[‘HTTP_X_FORWARDED_FOR’] );

$ _SERVER[‘REMOTE_ADDR’] = $ mte_xffaddrs[0];

}

fix wordpress error, display local ip address of localhost 3

Next save the file and upload it again.

fix WordPress wordpress to display ip address of localhost 4

You should now see the actual IP address of the client on the WordPress comment page and other locations, so you’ve fixed the WordPress error displaying the IP address of Localhost on successful user comments.

What happens to Code Snippet?

When the WordPress website is behind an HTTP proxy or using a load balancer, HTTP called “X-Forwarded-For” is used to store all IP addresses including the client’s real IP address in a chain. .

By default, the IP addresses in X-Forwarded-For are separated by commas and the first IP address in the string is always the client’s IP address.

What we do with the code snippet above is to get all of those IP addresses, divide them into separate parts and store them in arrays. $ mte_xffaddrs. Since the first IP address is associated with the client, we can use the Zero index and point it to REMOTE_ADDR in array $ _SERVER.

Fix incorrect IP address on WordPress using Plugin

If you don’t want to touch core WordPress files, you can use a plugin called Proxy Real IP. Although this plugin has not been updated for a long time, it still works quite well. Basically this plugin works like the code snippet above. The only difference is that the Proxy Real IP plugin uses functions preg_match not functions explode.

Just install and activate the plugin just like you would any other plugin. There are no settings pages or options to configure.

Download Proxy Real IP plugin to your computer and install it here: Download Proxy Real IP

fix wordpress error, display local ip address of localhost 5

Fix incorrect IP address on WordPress using Cloudflare

When behind a proxy like Cloudflare, WordPress can sometimes display Cloudflare’s IP rather than the actual IP of the visitor or the IP address of Localhost.

There is a simple way to fix this problem. Just paste the code below at the bottom of the file wp-config.php:

// Fix incorrect IP when using Cloudflare

if (array_key_exists (‘HTTP_CF_CONNECTING_IP’, $ _SERVER)) {

$ _SERVER[‘REMOTE_ADDR’] = $ _SERVER[‘HTTP_CF_CONNECTING_IP’];

}

fix wordpress error, display local ip address of localhost 6

The above code takes the real IP address of the client using HTTP_CF_CONNECTING_IP and only REMOTE_ADDR to that IP address.

Above Taimienphi.vn has shown you some ways to fix WordPress errors displaying the IP address of Localhost in user comments. Are you encountering this error? Do not forget to share your ideas with Taimienphi.vn offline.

If you are learning about WordPress and want to experience this website platform, you can first Install WordPress on localhost to get used to it and tinkering, learning about it.

https://thuthuat.taimienphi.vn/sua-loi-wordpress-hien-thi-dia-chi-ip-cua-localhost-32073n.aspx
After having installed successfully, you proceed to the design steps, create wordpress in your own opinion, the article to create WordPress will help you do this easier, I wish you success!

.

Add a Comment

Your email address will not be published. Required fields are marked *