取ip函数
function getIP ()
{
global $_SERVER;
if (getenv('HTTP_CLIENT_IP')) {
$ip = getenv('HTTP_CLIENT_IP');
} else if (getenv('HTTP_X_FORWARDED_FOR')) {
$ip = getenv('HTTP_X_FORWARDED_FOR');
} else if (getenv('REMOTE_ADDR')) {
$ip = getenv('REMOTE_ADDR');
} else {
$ip = $_SERVER['REMOTE_ADDR'];
}
return $ip;
}
用引用吧:
PHP代码:--------------------------------------------------------------------------------
<?
class IP{
function getIpAdr(&$ip){
$ip1=getenv("HTTP_X_FORWARDED_FOR");
$ip2=getenv("HTTP_CLIENT_IP");
$ip3=getenv("REMOTE_ADDR");
if($ip1&&$ip1!='unknow')
$ip=$ip1;
else if($ip2&&$ip2!='unknow')
$ip=$ip2;
else if($ip3&&$ip3!='unknow')
$ip=$ip3;
else
$ip='127.0.0.1';
}
}
$IP=new IP;
$c='';
$IP->getIpAdr(&$c);
echo $c;
?>
--------------------------------------------------------------------------------
这个最简单:
$ip=empty($_SERVER['HTTP_X_FORWARDED_FOR'])?$_SERVER['REMOTE_ADDR']:$_SERVER['HTTP_X_FORWARDED_FOR'];
$proxy=empty($_SERVER['HTTP_VIA'])?"未使用代理":"使用代理";