php.取得玩家IP


    /**
     * 取得玩家IP
     * @return string
     */
    private function getIP()
    {
        if(getenv('HTTP_X_FORWARDED_FOR')){
            $ip = getenv('HTTP_X_FORWARDED_FOR');
        }else{
            if (getenv('HTTP_CLIENT_IP')) {
                $ip = getenv('HTTP_CLIENT_IP');
            } elseif (getenv('HTTP_X_FORWARDED_FOR')) {
                $ip = getenv('HTTP_X_FORWARDED_FOR');
            } elseif (getenv('HTTP_X_FORWARDED')) {
                $ip = getenv('HTTP_X_FORWARDED');
            } elseif (getenv('HTTP_FORWARDED_FOR')) {
                $ip = getenv('HTTP_FORWARDED_FOR');

            } elseif (getenv('HTTP_FORWARDED')) {
                $ip = getenv('HTTP_FORWARDED');
            } else {
                $ip = $_SERVER['REMOTE_ADDR'];
            }
        }


        $comma_symbol = ',';
        if(strpos($ip, $comma_symbol)) {
            Log::write('过长的IP:'.$ip , Log::INFO);
            $ipArr = explode($comma_symbol, $ip);
            $ip = trim($ipArr[0]);
        }

        return $ip;
    }

你可能感兴趣的:(php.取得玩家IP)