做了CDN获取用户真实IP的函数代码(PHP与Asp设置方
asp函数代码
function checkip(checkstring)'用正则判断IP是否合法
dim re1
set re1=new RegExp
re1.pattern=”^[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}$”
re1.global=false
re1.Ignorecase=false
checkip=re1.test(checkstring)
set re1=nothing
end function
function get_cli_ip()'取真实IP函数,先 HTTP_CLIENT_IP 再 HTTP_X_FORWARDED_FOR 再 REMOTE_ADDR
dim client_ip
if checkip(Request.ServerVariables(”HTTP_CLIENT_IP”))=true then
get_cli_ip = checkip(Request.ServerVariables(”HTTP_CLIENT_IP”))
else
MyArray = split(Request.ServerVariables(”HTTP_X_FORWARDED_FOR”),”,”)
if ubound(MyArray)>=0 then
client_ip = trim(MyArray(0))
if checkip(client_ip)=true then
get_cli_ip = client_ip
exit function
end if
end if
get_cli_ip = Request.ServerVariables(”REMOTE_ADDR”)
end if
end function
discuz论坛取真实IP的php代码,其它类似,请参考稍做修改
(discuz修改include/mon.inc.php)
用以下这段代码:
if(getenv('HTTP_CLIENT_IP') && strcasecmp(getenv('HTTP_CLIENT_IP'),'unknown')) {
$onlineip = getenv('HTTP_CLIENT_IP');
} elseif(getenv('HTTP_X_FORWARDED_FOR') && strcasecmp(getenv('HTTP_X_FORWARDED_FOR'),
'unknown')) {
$testip = explode('.', getenv('HTTP_X_FORWARDED_FOR'));
if ($testip[0]=='192′ && $testip[1]=='168′) {
$onlineip = getenv('REMOTE_ADDR');
}
elseif($testip[0]=='10′) {
$onlineip = getenv('REMOTE_ADDR');
}
else {
$onlineip = getenv('HTTP_X_FORWARDED_FOR');
}
//gamesir hack end} elseif(getenv('REMOTE_ADDR') && strcasecmp(getenv('REMOTE_ADDR'),
'unknown')) {
$onlineip = getenv('REMOTE_ADDR');
} elseif(isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER
['REMOTE_ADDR'],'unknown')) {
//by Johnny
$tmp_ip = explode(',',$_SERVER['HTTP_X_FORWARDED_FOR']);
$tmp_ip1 = explode(',',$tmp_ip[0]);
if ($tmp_ip1[0] =='192′ && $tmp_ip1[1] =='168′) {
$onlineip = getenv('REMOTE_ADDR');
}else if($tmp_ip1[0]=='10′) {
$onlineip = getenv('REMOTE_ADDR');
}
else{
$onlineip = $tmp_ip[0];
}
unset($tmp_ip);unset($tmp_ip1);
}
替换这段代码:
if(getenv('HTTP_CLIENT_IP') && strcasecmp(getenv('HTTP_CLIENT_IP'),'unknown')) {
$onlineip = getenv('HTTP_CLIENT_IP');
} elseif(getenv('HTTP_X_FORWARDED_FOR') && strcasecmp(getenv('HTTP_X_FORWARDED_FOR'),
'unknown')) {
$onlineip = getenv('HTTP_X_FORWARDED_FOR');
} elseif(getenv('REMOTE_ADDR') && strcasecmp(getenv('REMOTE_ADDR'),'unknown')) {
$onlineip = getenv('REMOTE_ADDR');
} elseif(isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER
['REMOTE_ADDR'],'unknown')) {
$onlineip = $_SERVER['REMOTE_ADDR'];
}
编程语言
- 如何快速学会编程 如何快速学会ug编程
- 免费学编程的app 推荐12个免费学编程的好网站
- 电脑怎么编程:电脑怎么编程网咯游戏菜单图标
- 如何写代码新手教学 如何写代码新手教学手机
- 基础编程入门教程视频 基础编程入门教程视频华
- 编程演示:编程演示浦丰投针过程
- 乐高编程加盟 乐高积木编程加盟
- 跟我学plc编程 plc编程自学入门视频教程
- ug编程成航林总 ug编程实战视频
- 孩子学编程的好处和坏处
- 初学者学编程该从哪里开始 新手学编程从哪里入
- 慢走丝编程 慢走丝编程难学吗
- 国内十强少儿编程机构 中国少儿编程机构十强有
- 成人计算机速成培训班 成人计算机速成培训班办
- 孩子学编程网上课程哪家好 儿童学编程比较好的
- 代码编程教学入门软件 代码编程教程