Symfony\Component\HttpFoundation\Request::getClientIp PHP Method

getClientIp() public method

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.
See also: getClientIps()
See also: http://en.wikipedia.org/wiki/X-Forwarded-For
public getClientIp ( ) : string
return string The client IP address
    public function getClientIp()
    {
        $ipAddresses = $this->getClientIps();

        return $ipAddresses[0];
    }

Usage Example

 public function matches(Request $request)
 {
     if (!$this->language) {
         throw new \LogicException('Unable to match the request as the expression language is not available.');
     }
     return $this->language->evaluate($this->expression, array('request' => $request, 'method' => $request->getMethod(), 'path' => rawurldecode($request->getPathInfo()), 'host' => $request->getHost(), 'ip' => $request->getClientIp(), 'attributes' => $request->attributes->all())) && parent::matches($request);
 }
All Usage Examples Of Symfony\Component\HttpFoundation\Request::getClientIp