时间:2021-07-01 10:21:17 帮助过:69人阅读
NOTIC: [8] Undefined variable: ip
NOTIC: [8] Undefined variable: ips
谁能帮忙改下~~
function Getip() {
if (!empty($_SERVER["HTTP_CLIENT_IP"])) {
$ip = $_SERVER["HTTP_CLIENT_IP"];
}
if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {//获取代理ip
$ips = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
}
if ($ip) {
$ips = array_unshift($ips, $ip);
}
$count = count($ips);
for ($i = 0; $i < $count; $i++) {
if (!preg_match("/^(10|172\.16|192\.168)\./i", $ips[$i])) {//排除局域网ip
$ip = $ips[$i];
break;
}
}
$tip = $ip ? $ip : $_SERVER['REMOTE_ADDR'];
if ($tip == "127.0.0.1") {//获得本地真实IP
return $this -> get_onlineip();
} else {
return $tip;
}
}
ip 和 ips, 两个变量都报未定义:
NOTIC: [8] Undefined variable: ip
NOTIC: [8] Undefined variable: ips
谁能帮忙改下~~
function Getip() {
if (!empty($_SERVER["HTTP_CLIENT_IP"])) {
$ip = $_SERVER["HTTP_CLIENT_IP"];
}
if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {//获取代理ip
$ips = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
}
if ($ip) {
$ips = array_unshift($ips, $ip);
}
$count = count($ips);
for ($i = 0; $i < $count; $i++) {
if (!preg_match("/^(10|172\.16|192\.168)\./i", $ips[$i])) {//排除局域网ip
$ip = $ips[$i];
break;
}
}
$tip = $ip ? $ip : $_SERVER['REMOTE_ADDR'];
if ($tip == "127.0.0.1") {//获得本地真实IP
return $this -> get_onlineip();
} else {
return $tip;
}
}
如果你仅仅是想忽略这个问题的话,那就调低报错等级,在php.ini中设置error_reporting = E_ERROR或者直接在php中设置error_reporting(E_Error);
ThinkPHP解决这个就算了吧,TP本身就没处理这些问题,要处理那么使用的时候都得先通过isset验证一下...
判读这两个变量是否有值,如果有就赋值,没有就为空,按照这个试试