php获取用户IP地址

具体请下载

<?php
require_once './Getip/qqwry.class.php';
$ip 		=	get_user_ip();
//$ip 		=	'58.61.214.48';
$QQWry		=	new QQWry;
$ifErr		=	$QQWry->QQWry($ip); 
$location	=	$QQWry->Country.$QQWry->Local;
if(!empty($location))
{
	$location =	iconv('GB2312', 'UTF-8', $location);
}
else
{
	$location = '未知地区';
}
 
 
/*
	 * 获取用户的Ip地址
	 */
	function get_user_ip()
    {
		/*
	        if($_SERVER["HTTP_X_REAL_IP"])
			{
				$ip	=	$_SERVER["HTTP_X_REAL_IP"];
			}
			else
		*/
		if($HTTP_SERVER_VARS["HTTP_X_FORWARDED_FOR"])
        {                                             
               $ip = $HTTP_SERVER_VARS["HTTP_X_FORWARDED_FOR"];
        }                                             
        elseif($HTTP_SERVER_VARS["HTTP_CLIENT_IP"])   
        {                                             
               $ip = $HTTP_SERVER_VARS["HTTP_CLIENT_IP"];
        }                                             
        elseif ($HTTP_SERVER_VARS["REMOTE_ADDR"])      
        {                                             
               $ip = $HTTP_SERVER_VARS["REMOTE_ADDR"];  
        }                                             
        elseif (getenv("HTTP_X_FORWARDED_FOR"))          
        {                                             
               $ip = getenv("HTTP_X_FORWARDED_FOR");  
        }                                             
        elseif (getenv("HTTP_CLIENT_IP"))                
        {                                             
               $ip = getenv("HTTP_CLIENT_IP");  
        }         
        elseif (getenv("REMOTE_ADDR"))  {                                             
               $ip = getenv("REMOTE_ADDR");
        }      
        else    {                                             
               $ip = "Unknown";   
        } 
 
        return $ip;
    }
?>
<div style='font-size:18px;font-weight: 500;font-family: "microsoft yahei";margin-top:10px;'>
                    我的IP地址:<?php echo $ip; ?><br /><br />
                    所属地区:&nbsp;&nbsp;<?php echo $location; ?>
</div>

Related posts:

Leave a Reply

Your email address will not be published.