Fix – WordPress Showing Localhost IP(127.0.0.1) for Comment Author Instead of Real

comment-author-ip

To fix this problem,

  1. Login to FTP/SFTP
  2. Go to public_html folder
  3. Edit wp-config.php
  4. Add below line
  5. Save Changes.
/** Required Code for showing correct IP address */
 if ( !empty( $_SERVER['HTTP_CLIENT_IP'] ) ) { //check ip from share internet
 $ip = $_SERVER['HTTP_CLIENT_IP'];
 } elseif ( !empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) { // to check ip is pass from proxy, also could be used ['HTTP_X_REAL_IP ']
 $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
 } else {
 $ip = $_SERVER['REMOTE_ADDR'];
 }
 $_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_X_FORWARDED_FOR'];

Mark: This common problem I had noticed on Cloudways web hosting. However, it is very optimized for better performance.

Subscribe our blog via Email
Get instant updates of our new blog post directly at your Mailbox.

Add a Comment

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

By commenting on this article, you agree to our .