[HttpFoundation] added Request::getClientIp()
This commit is contained in:
parent
f3caaf9638
commit
15cd2643c0
@ -262,6 +262,26 @@ class Request
|
||||
$this->session = $session;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the client IP address.
|
||||
*
|
||||
* @param Boolean $proxy Whether the current request has been made behind a proxy or not
|
||||
*
|
||||
* @return string The client IP address
|
||||
*/
|
||||
public function getClientIp($proxy = false)
|
||||
{
|
||||
if ($proxy) {
|
||||
if ($this->server->has('HTTP_CLIENT_IP')) {
|
||||
return $this->server->get('HTTP_CLIENT_IP');
|
||||
} elseif ($this->server->has('HTTP_X_FORWARDED_FOR')) {
|
||||
return $this->server->get('HTTP_X_FORWARDED_FOR');
|
||||
}
|
||||
}
|
||||
|
||||
return $this->server->get('REMOTE_ADDR');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns current script name.
|
||||
*
|
||||
|
Reference in New Issue
Block a user