Fixes issue #1815 - input::ip_address() returns incorrect IP behind prox... #1816

Merged
merged 1 commit into from Sep 20, 2012

Conversation

Projects
None yet
2 participants
Contributor

assembledadam commented Sep 20, 2012

...y when multiple IPs are sent back from the server in HTTP_X_FORWARDED_FOR.

Problematic code:

if (strpos($this->ip_address, ',') !== FALSE)
{
$x = explode(',', $this->ip_address);
$this->ip_address = trim(end($x));
}

This is due to it taking the last IP.

As far as I can tell (let http://en.wikipedia.org/wiki/X-Forwarded-For be my witness), the client is generally listed as the first IP address, not the last, so this is a simple case of changing the line:

$this->ip_address = trim(end($x));
to
$this->ip_address = trim($x[0]);

[TESTED USING APACHE/HAPROXY]

narfbg added a commit that referenced this pull request Sep 20, 2012

Merge pull request #1816 from progmedia/develop
Fixes issue #1815 - input::ip_address() returns incorrect IP behind prox...

@narfbg narfbg merged commit 4cfde87 into bcit-ci:develop Sep 20, 2012

1 check passed

default The Travis build passed
Details

nonchip pushed a commit to nonchip/CodeIgniter that referenced this pull request Jun 29, 2013

Merge pull request #1816 from progmedia/develop
Fixes issue #1815 - input::ip_address() returns incorrect IP behind prox...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment