优化一段利用PHP获取真实IP地址源码
functionGetIP(){if(getenv("HTTP_CLIENT_IP")&&strcasecmp(getenv("HTTP_CLIENT_IP"),"unk...
function GetIP(){
if (getenv("HTTP_CLIENT_IP") && strcasecmp(getenv("HTTP_CLIENT_IP"), "unknown"))
$ip = getenv("HTTP_CLIENT_IP");
else if (getenv("HTTP_X_FORWARDED_FOR") && strcasecmp(getenv("HTTP_X_FORWARDED_FOR"), "unknown"))
$ip = getenv("HTTP_X_FORWARDED_FOR");
else if (getenv("REMOTE_ADDR") && strcasecmp(getenv("REMOTE_ADDR"), "unknown"))
$ip = getenv("REMOTE_ADDR");
else if (isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], "unknown"))
$ip = $_SERVER['REMOTE_ADDR'];
else
$ip = "unknown";
return($ip);
echo GetIP();
}
----------------------------分割线--------------------------
$url='http://(淘宝IP库)/service/getIpInfo.php?ip='.$ip;
........
上面那段能过滤代理IP,获取到真实的IP地址, 分割线下面是提交到淘宝IP库,我们原来用的是$ip = $_SERVER["REMOTE_ADDR"];这么一句,获取到的IP不准确,换成上面那段厉害的。麻烦大神们帮忙把他们拼接一下,谢谢 展开
if (getenv("HTTP_CLIENT_IP") && strcasecmp(getenv("HTTP_CLIENT_IP"), "unknown"))
$ip = getenv("HTTP_CLIENT_IP");
else if (getenv("HTTP_X_FORWARDED_FOR") && strcasecmp(getenv("HTTP_X_FORWARDED_FOR"), "unknown"))
$ip = getenv("HTTP_X_FORWARDED_FOR");
else if (getenv("REMOTE_ADDR") && strcasecmp(getenv("REMOTE_ADDR"), "unknown"))
$ip = getenv("REMOTE_ADDR");
else if (isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], "unknown"))
$ip = $_SERVER['REMOTE_ADDR'];
else
$ip = "unknown";
return($ip);
echo GetIP();
}
----------------------------分割线--------------------------
$url='http://(淘宝IP库)/service/getIpInfo.php?ip='.$ip;
........
上面那段能过滤代理IP,获取到真实的IP地址, 分割线下面是提交到淘宝IP库,我们原来用的是$ip = $_SERVER["REMOTE_ADDR"];这么一句,获取到的IP不准确,换成上面那段厉害的。麻烦大神们帮忙把他们拼接一下,谢谢 展开
1个回答
2016-07-29
展开全部
function GetIP(){
if (getenv("HTTP_CLIENT_IP") && strcasecmp(getenv("HTTP_CLIENT_IP"), "unknown"))
$ip = getenv("HTTP_CLIENT_IP");
else if (getenv("HTTP_X_FORWARDED_FOR") && strcasecmp(getenv("HTTP_X_FORWARDED_FOR"), "unknown"))
$ip = getenv("HTTP_X_FORWARDED_FOR");
else if (getenv("REMOTE_ADDR") && strcasecmp(getenv("REMOTE_ADDR"), "unknown"))
$ip = getenv("REMOTE_ADDR");
else if (isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], "unknown"))
$ip = $_SERVER['REMOTE_ADDR'];
else
$ip = "unknown";
return($ip);
}
$url='http://(淘宝IP库)/service/getIpInfo.php?ip='.GetIP();
云创
2023-07-25 广告
2023-07-25 广告
要找到一家更省钱的代码静态分析服务,可以考虑以下几个方面:1. 了解自身的需求和预算:首先需要了解自己的项目对代码静态分析服务的需求,以及可承受的预算范围。这将有助于缩小选择范围,找到适合自己的服务。2. 调查市场上的竞争情况:了解市场上提...
点击进入详情页
本回答由云创提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询