Supesite使用CDN后获取真实IP 办法
include/main.inc.php文件,这部分
if(getenv('HTTP_CLIENT_IP') && strcasecmp(getenv('HTTP_CLIENT_IP'), 'unknown')) {
$_SGLOBAL['onlineip'] = getenv('HTTP_CLIENT_IP');
} elseif(getenv('HTTP_X_FORWARDED_FOR') && strcasecmp(getenv('HTTP_X_FORWARDED_FOR'), 'unknown')) {
$_SGLOBAL['onlineip'] = getenv('HTTP_X_FORWARDED_FOR');
} elseif(getenv('REMOTE_ADDR') && strcasecmp(getenv('REMOTE_ADDR'), 'unknown')) {
$_SGLOBAL['onlineip'] = getenv('REMOTE_ADDR');
} elseif(isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], 'unknown')) {
$_SGLOBAL['onlineip'] = $_SERVER['REMOTE_ADDR'];
}
替换成
function get_real_ip()
{
$ip=false;
if(!empty($_SERVER["HTTP_CLIENT_IP"]))
{
$ip = $_SERVER["HTTP_CLIENT_IP"];
}
if (!empty($_SERVER['HTTP_X_FORWARDED_FOR']))
{
$ips = explode (", ", $_SERVER['HTTP_X_FORWARDED_FOR']);
if ($ip)
{
array_unshift($ips, $ip); $ip = FALSE;
}
for ($i = 0; $i < count($ips); $i++)
{
if (!eregi ("^(10|172\.16|192\.168)\.", $ips[$i]))
{
$ip = $ips[$i];
break;
}
}
}
return ($ip ? $ip : $_SERVER['REMOTE_ADDR']);
}
$_SGLOBAL['onlineip'] = get_real_ip();
Discuz!使用CDN后获取真实IP办法
nclude/common.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')) {
$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'];
}
替换为:
function get_real_ip()
{
$ip=false;
if(!empty($_SERVER["HTTP_CLIENT_IP"]))
{
$ip = $_SERVER["HTTP_CLIENT_IP"];
}
if (!empty($_SERVER['HTTP_X_FORWARDED_FOR']))
{
$ips = explode (", ", $_SERVER['HTTP_X_FORWARDED_FOR']);
if ($ip)
{
array_unshift($ips, $ip); $ip = FALSE;
}
for ($i = 0; $i < count($ips); $i++)
{
if (!eregi ("^(10|172\.16|192\.168)\.", $ips[$i]))
{
$ip = $ips[$i];
break;
}
}
}
return ($ip ? $ip : $_SERVER['REMOTE_ADDR']);
}
$onlineip = get_real_ip();
DZ注册用户IP和邀请码拥有者IP相同的解决办法
方法A:
register.php 200行
showmessage('register_invite_iperror');
改为
//showmessage('register_invite_iperror');
方法B:
在include/common.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')) {
$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'];
}
替换成:
代码:
$onlineip=getenv('HTTP_X_FORWARD_FOR');
--------------------
做了CDN的ASP网站如何取到用户真实IP程序
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