src/Control/Middleware/TrustedProxyMiddleware.php
protected function getIPFromHeaderValue($headerValue)
    {
        // Sometimes the IP from a load balancer could be "x.x.x.x, y.y.y.y, z.z.z.z"
        // so we need to find the most likely candidate
        $ips = preg_split('/\s*,\s*/', $headerValue);

        // Prioritise filters
        $filters = [
            FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE,
            FILTER_FLAG_NO_PRIV_RANGE,
            null
        ];
        foreach ($filters as $filter) {
            // Find best IP
            foreach ($ips as $ip) {
                if (filter_var($ip, FILTER_VALIDATE_IP, $filter)) {
                    return $ip;
                }
            }
        }
        return null;
    }
protected function getIPFromHeaderValue($headerValue)
    {
        // Sometimes the IP from a load balancer could be "x.x.x.x, y.y.y.y, z.z.z.z"
        // so we need to find the most likely candidate
        $ips = preg_split('/\s*,\s*/', $headerValue);

        // Prioritise filters
        $filters = [
            FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE,
            FILTER_FLAG_NO_PRIV_RANGE,
            null
        ];
        foreach ($filters as $filter) {
            // Find best IP
            foreach ($ips as $ip) {
                if (filter_var($ip, FILTER_VALIDATE_IP, $filter)) {
                    return $ip;
                }
            }
        }
        return null;
    }
protected function getIPFromHeaderValue ( $ headerValue ) { // Sometimes the IP from a load balancer could be "x.x.x.x, y.y.y.y, z.z.z.z" // so we need to find the most likely candidate $ ips = preg_split ( '/\s*,\s*/' , $ headerValue ) ; // Prioritise filters $ filters = [ FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE , FILTER_FLAG_NO_PRIV_RANGE , null ] ; foreach ( $ filters as $ filter ) { // Find best IP foreach ( $ ips as $ ip ) { if ( filter_var ( $ ip , FILTER_VALIDATE_IP , $ filter ) ) { return $ ip ; } } } return null ; }
Extract an IP address from a header value that has been obtained.
Accepts single IP or comma separated string of IPs

@param string $headerValue The value from a trusted header
@return string The IP address
Extract an IP address from a header value that has been obtained . Accepts single IP or comma separated string of IPs