EllisLab/CodeIgniter — Issue #907: Proxy Ip reported instead of User Ip
Author: aeperezt
Created: 2012-01-09 18:55:44+00:00
State: open

When behind a loadbalance (rackspace on this case) the HTTP_X_FORWARDED_FOR variable is not reported properlly so I get the load balancer Ip instead if the user Ip changer the HTTP_X_FORWARDED_FOR to HTTP_X_CLUSTER_CLIENT_IP solved issue. Think you should include HTTP_X_CLUSTER_CLIENT_IP as one of the options for future cases.

if (config_item('proxy_ips') != '' && $this->server('HTTP_X_CLUSTER_CLIENT_IP') && $this->server('REMOTE_ADDR'))
{

$proxies = preg_split('/[\s,]/', config_item('proxy_ips'), -1, PREG_SPLIT_NO_EMPTY);
$proxies = is_array($proxies) ? $proxies : array($proxies);
$this->ip_address = in_array($_SERVER['REMOTE_ADDR'], $proxies) ? $_SERVER['HTTP_X_CLUSTER_CLIENT_IP'] : $_SERVER['REMOTE_ADDR'];
}
elseif ($this->server('REMOTE_ADDR') AND $this->server('HTTP_CLIENT_IP'))
{
$this->ip_address = $_SERVER['HTTP_CLIENT_IP'];
}
elseif ($this->server('REMOTE_ADDR'))
{
$this->ip_address = $_SERVER['REMOTE_ADDR'];
}
elseif ($this->server('HTTP_CLIENT_IP'))
{
$this->ip_address = $_SERVER['HTTP_CLIENT_IP'];
}
elseif ($this->server('HTTP_X_CLUSTER_CLIENT_IP'))
{
$this->ip_address = $_SERVER['HTTP_X_CLUSTER_CLIENT_IP'];
}