Skip to content

Commit

Permalink
Follow X-Forwarded for rules, to pick the correct client IP
Browse files Browse the repository at this point in the history
  • Loading branch information
bajb committed Apr 24, 2015
1 parent 2922be6 commit 154b7e6
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion src/Http/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ public function path($depth = null)
/**
* Retrieve a section of the path
*
* @param int $offset
* @param int $offset
* @param null $limit
*
* @return string
Expand Down Expand Up @@ -317,4 +317,31 @@ public function referrer($default = null)
$this->server->get('HTTP_REFERER', $default)
);
}

/**
* Returns the client IP address.
*
* This method can read the client IP address from the "X-Forwarded-For"
* header when trusted proxies were set via "setTrustedProxies()". The
* "X-Forwarded-For" header value is a comma+space separated list of IP
* addresses, the left-most being the original client, and each successive
* proxy that passed the request adding the IP address where it received the
* request from.
*
* If your reverse proxy uses a different header name than "X-Forwarded-For",
* ("Client-Ip" for instance), configure it via "setTrustedHeaderName()" with
* the "client-ip" key.
*
* @return string The client IP address
*
* @see getClientIps()
* @see http://en.wikipedia.org/wiki/X-Forwarded-For
*
* @api
*/
public function getClientIp()
{
$ipAddresses = $this->getClientIps();
return end($ipAddresses);
}
}

0 comments on commit 154b7e6

Please sign in to comment.