protected function determineClientIpAddress($request)
    {
        $ipAddress = null;

        $serverParams = $request->getServerParams();
        if (isset($serverParams['REMOTE_ADDR']) && $this->isValidIpAddress($serverParams['REMOTE_ADDR'])) {
            $ipAddress = $serverParams['REMOTE_ADDR'];
        }

        $checkProxyHeaders = $this->checkProxyHeaders;
        if ($checkProxyHeaders && !empty($this->trustedProxies)) {
            if (!in_array($ipAddress, $this->trustedProxies)) {
                $checkProxyHeaders = false;
            }
        }

        if ($checkProxyHeaders) {
            foreach ($this->headersToInspect as $header) {
                if ($request->hasHeader($header)) {
                    $ip = trim(current(explode(',', $request->getHeaderLine($header))));
                    if ($this->isValidIpAddress($ip)) {
                        $ipAddress = $ip;
                        break;
                    }
                }
            }
        }

        return $ipAddress;
    }
protected function determineClientIpAddress($request)
    {
        $ipAddress = null;

        $serverParams = $request->getServerParams();
        if (isset($serverParams['REMOTE_ADDR']) && $this->isValidIpAddress($serverParams['REMOTE_ADDR'])) {
            $ipAddress = $serverParams['REMOTE_ADDR'];
        }

        $checkProxyHeaders = $this->checkProxyHeaders;
        if ($checkProxyHeaders && !empty($this->trustedProxies)) {
            if (!in_array($ipAddress, $this->trustedProxies)) {
                $checkProxyHeaders = false;
            }
        }

        if ($checkProxyHeaders) {
            foreach ($this->headersToInspect as $header) {
                if ($request->hasHeader($header)) {
                    $ip = trim(current(explode(',', $request->getHeaderLine($header))));
                    if ($this->isValidIpAddress($ip)) {
                        $ipAddress = $ip;
                        break;
                    }
                }
            }
        }

        return $ipAddress;
    }
protected function determineClientIpAddress ( $ request ) { $ ipAddress = null ; $ serverParams = $ request -> getServerParams ( ) ; if ( isset ( $ serverParams [ 'REMOTE_ADDR' ] ) && $ this -> isValidIpAddress ( $ serverParams [ 'REMOTE_ADDR' ] ) ) { $ ipAddress = $ serverParams [ 'REMOTE_ADDR' ] ; } $ checkProxyHeaders = $ this -> checkProxyHeaders ; if ( $ checkProxyHeaders && ! empty ( $ this -> trustedProxies ) ) { if ( ! in_array ( $ ipAddress , $ this -> trustedProxies ) ) { $ checkProxyHeaders = false ; } } if ( $ checkProxyHeaders ) { foreach ( $ this -> headersToInspect as $ header ) { if ( $ request -> hasHeader ( $ header ) ) { $ ip = trim ( current ( explode ( ',' , $ request -> getHeaderLine ( $ header ) ) ) ) ; if ( $ this -> isValidIpAddress ( $ ip ) ) { $ ipAddress = $ ip ; break ; } } } } return $ ipAddress ; }
Find out the client's IP address from the headers available to us

@param  ServerRequestInterface $request PSR-7 Request
@return string
Find out the client s IP address from the headers available to us