当前位置 : 主页 > 网络编程 > PHP >

获取ip

来源:互联网 收集:自由互联 发布时间:2021-06-28
获取ip /** * 获取ip * @return string */protected function getIP() { if (getenv('HTTP_CLIENT_IP')) {# 检查客户端IP $ip = getenv('HTTP_CLIENT_IP'); } elseif (getenv('HTTP_X_FORWARDED_FOR')) {# 检查系统IP $ip = getenv('HTTP_X_FORW
获取ip
/**
     * 获取ip
     * @return string
     */
protected function getIP()
    {
        if (getenv('HTTP_CLIENT_IP')) {# 检查客户端IP
            $ip = getenv('HTTP_CLIENT_IP');
        } elseif (getenv('HTTP_X_FORWARDED_FOR')) {#  检查系统IP
            $ip = getenv('HTTP_X_FORWARDED_FOR');
        } elseif (getenv('HTTP_X_FORWARDED')) {#  检查IP
            $ip = getenv('HTTP_X_FORWARDED');
        } elseif (getenv('HTTP_FORWARDED_FOR')) {#  检查IP
            $ip = getenv('HTTP_FORWARDED_FOR');
        } elseif (getenv('HTTP_FORWARDED')) {#  检查IP
            $ip = getenv('HTTP_FORWARDED');
        } else {# 检查系统内置IP
            $ip = $_SERVER['REMOTE_ADDR'];
        }#返回IP

        return $ip;

    }
网友评论