protected function getForwardedIp(ServerRequestInterface $request, $ip)
    {
        $ips = [$ip];
        
        $forwardedFor = $this->splitIps($request->getHeaderLine('X-Forwarded-For'));
        $forwarded = $this->extractForFromForwardedHeader($request->getHeaderLine('Forwarded'));
        $clientIp = $this->splitIps($request->getHeaderLine('Client-Ip'));
        
        if (!$this->areAllTheSame($forwardedFor, $forwarded, $clientIp)) {
            $msg = 'Only one of `X-Forwarded-For`, `Forwarded` or `Client-Ip` headers should be set';
            throw new \RuntimeException($msg);
        }
        
        $fwd = $forwardedFor ?: $forwarded ?: $clientIp;
        
        if ($fwd) {
            $ips = array_merge($ips, $fwd);
        }
        
        return $this->getTrustedForwardedIp($ips);
    }
protected function getForwardedIp(ServerRequestInterface $request, $ip)
    {
        $ips = [$ip];
        
        $forwardedFor = $this->splitIps($request->getHeaderLine('X-Forwarded-For'));
        $forwarded = $this->extractForFromForwardedHeader($request->getHeaderLine('Forwarded'));
        $clientIp = $this->splitIps($request->getHeaderLine('Client-Ip'));
        
        if (!$this->areAllTheSame($forwardedFor, $forwarded, $clientIp)) {
            $msg = 'Only one of `X-Forwarded-For`, `Forwarded` or `Client-Ip` headers should be set';
            throw new \RuntimeException($msg);
        }
        
        $fwd = $forwardedFor ?: $forwarded ?: $clientIp;
        
        if ($fwd) {
            $ips = array_merge($ips, $fwd);
        }
        
        return $this->getTrustedForwardedIp($ips);
    }
protected function getForwardedIp ( ServerRequestInterface $ request , $ ip ) { $ ips = [ $ ip ] ; $ forwardedFor = $ this -> splitIps ( $ request -> getHeaderLine ( 'X-Forwarded-For' ) ) ; $ forwarded = $ this -> extractForFromForwardedHeader ( $ request -> getHeaderLine ( 'Forwarded' ) ) ; $ clientIp = $ this -> splitIps ( $ request -> getHeaderLine ( 'Client-Ip' ) ) ; if ( ! $ this -> areAllTheSame ( $ forwardedFor , $ forwarded , $ clientIp ) ) { $ msg = 'Only one of `X-Forwarded-For`, `Forwarded` or `Client-Ip` headers should be set' ; throw new \ RuntimeException ( $ msg ) ; } $ fwd = $ forwardedFor ? : $ forwarded ? : $ clientIp ; if ( $ fwd ) { $ ips = array_merge ( $ ips , $ fwd ) ; } return $ this -> getTrustedForwardedIp ( $ ips ) ; }
Get the forwarded ip

@param ServerRequestInterface $request
@param string                 $ip       Connected IP
@return string|null
Get the forwarded ip