src/Request.php
public static function getClientIP()
    {
        if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])
            && isset($_SERVER['REMOTE_ADDR'])
            && in_array($_SERVER['REMOTE_ADDR'], Request::$trustedProxies)
        )
        {
            // Format: "X-Forwarded-For: client1, proxy1, proxy2"
            $clientIps = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);

            return array_shift($clientIps);
        }
        elseif (isset($_SERVER['HTTP_CLIENT_IP'])
            && isset($_SERVER['REMOTE_ADDR'])
            && in_array($_SERVER['REMOTE_ADDR'], Request::$trustedProxies)
        )
        {
            $clientIps = explode(',', $_SERVER['HTTP_CLIENT_IP']);

            return array_shift($clientIps);
        }
        elseif (isset($_SERVER['REMOTE_ADDR']))
        {
            return $_SERVER['REMOTE_ADDR'];
        }

        return '0.0.0.0';
    }
public static function getClientIP()
    {
        if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])
            && isset($_SERVER['REMOTE_ADDR'])
            && in_array($_SERVER['REMOTE_ADDR'], Request::$trustedProxies)
        )
        {
            // Format: "X-Forwarded-For: client1, proxy1, proxy2"
            $clientIps = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);

            return array_shift($clientIps);
        }
        elseif (isset($_SERVER['HTTP_CLIENT_IP'])
            && isset($_SERVER['REMOTE_ADDR'])
            && in_array($_SERVER['REMOTE_ADDR'], Request::$trustedProxies)
        )
        {
            $clientIps = explode(',', $_SERVER['HTTP_CLIENT_IP']);

            return array_shift($clientIps);
        }
        elseif (isset($_SERVER['REMOTE_ADDR']))
        {
            return $_SERVER['REMOTE_ADDR'];
        }

        return '0.0.0.0';
    }
读取客户端IP地址

@return string