Zend Framework获取客户端ip

早上无聊翻看zend framework的源代码,发现在http_request类中有一个获取客户端ip的方法,之前都不知道都是自己写的。贴出来一下:

 /**
     * Get the client's IP addres
     *
     * @param  boolean $checkProxy
     * @return string
     */
    public function getClientIp($checkProxy = true)
    {
        if ($checkProxy && $this->getServer('HTTP_CLIENT_IP') != null) {
            $ip = $this->getServer('HTTP_CLIENT_IP');
        } else if ($checkProxy && $this->getServer('HTTP_X_FORWARDED_FOR') != null) {
            $ip = $this->getServer('HTTP_X_FORWARDED_FOR');
        } else {
            $ip = $this->getServer('REMOTE_ADDR');
        }

        return $ip;
    }

PS:zend framework的确做得不错,还符合国人习惯。。

你可能感兴趣的:(Zend Framework获取客户端ip)