The Burton Tech Journal

Tag: private ip

Fix for Incorrect IP Addresses in WordPress Comments

by on Nov.30, 2008, under PHP, Security, Spam, Wordpress

Due to a web server’s proxy or the server is clustered (particularly with “cloud” based hosting), the server variable WordPress uses does not reflect the IP address of the posting user. Instead the IP address is the internal private LAN address of the web server’s network. This causes problems when trying to blacklist spammers or use a plugin like Akismet.

To workaround this IP address issue, you will need to modify the $_SERVER[“REMOTE_ADDR”] variable by editing the “wp-config.php” in your WordPress root directory:

  1. Download and backup your wp-config.php configuration file.
  2. Open your WordPress configuration file and add the following code after the named constant definitions:

/* By Grant Burton @ BURTONTECH.COM (11-30-2008): IP-Proxy-Cluster Fix */
/* Updated on 7/30/2015 to reflect current IANA addresses */
function checkIP($ip) {
if (!empty($ip) && ip2long($ip)!=-1 && ip2long($ip)!=false) {
$private_ips = array (array('',''),

</p><p>foreach ($private_ips as $r) {
$min = ip2long($r[0]);
$max = ip2long($r[1]);
if ((ip2long($ip) >= $min) && (ip2long($ip) < = $max)) return false; } return true; } else { return false; } } function determineIP() { if (checkIP($_SERVER["HTTP_CLIENT_IP"])) { return $_SERVER["HTTP_CLIENT_IP"]; } foreach (explode(",",$_SERVER["HTTP_X_FORWARDED_FOR"]) as $ip) { if (checkIP(trim($ip))) { return $ip; } } if (checkIP($_SERVER["HTTP_X_FORWARDED"])) { return $_SERVER["HTTP_X_FORWARDED"]; } elseif (checkIP($_SERVER["HTTP_X_CLUSTER_CLIENT_IP"])) { return $_SERVER["HTTP_X_CLUSTER_CLIENT_IP"]; } elseif (checkIP($_SERVER["HTTP_FORWARDED_FOR"])) { return $_SERVER["HTTP_FORWARDED_FOR"]; } elseif (checkIP($_SERVER["HTTP_FORWARDED"])) { return $_SERVER["HTTP_FORWARDED"]; } else { return $_SERVER["REMOTE_ADDR"]; } } //Override server variable for WordPress comments $_SERVER["REMOTE_ADDR"] = determineIP(); 

Caution should be used since many of these variables can be spoofed by a client, so don’t use them for authentication or access control. The functions could be easily adapted for other web applications though.


4 Comments :, , , , , , , , , , , , , , , more...

Non-Routable (Private) IP Addresses

by on Nov.29, 2008, under Networking, Security

RFC 1597 provides for a group of Internet Networks that will never be assigned. The private addresses will also not be routable through the Internet, preventing communication with networks on other subnets. The implementation of the Private IP address scope makes it the proper choice for use on company Intranets and for home/SOHO networks. These IP addresses have been specifically selected to use when it isn’t necessary or desired for computers on the Internet to connect to IPv4 based deviced on your network.

With use of a proxy server, firewall, or router, users and devices with non-routable IP addresses are allowed to access the Internet through a single IP address provided by their service provider. The devices achieve this through the process of Network Address Translation (NAT), allowing the nonroutable addresses to communicate with Internet-based, routable, Public IP addresses.

Reserved IP addresses for Private Networks are the following: – – –

A complete and current list of all IP Address Allocations can be found at the Internet Assigned Numbers Authority’s (IANA) website:

Leave a Comment :, , , , , , , , , , , more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!


A few highly recommended websites...