美文网首页我爱编程
php.取得玩家IP

php.取得玩家IP

作者: 程序猿阿乐 | 来源:发表于2018-08-09 16:31 被阅读0次
    
        /**
         * 取得玩家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

        本文链接:https://www.haomeiwen.com/subject/kqdcbftx.html