Rumah > Artikel > pembangunan bahagian belakang > ThinkPHP 3.2.3 怎么才能解决‘Undefined variable’这个错误呢?
ip 和 ips, 两个变量都报未定义:
NOTIC: [8] Undefined variable: ip
NOTIC: [8] Undefined variable: ips
谁能帮忙改下~~
<code>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 get_onlineip(); } else { return $tip; } }</code>
ip 和 ips, 两个变量都报未定义:
NOTIC: [8] Undefined variable: ip
NOTIC: [8] Undefined variable: ips
谁能帮忙改下~~
<code>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 get_onlineip(); } else { return $tip; } }</code>
如果你仅仅是想忽略这个问题的话,那就调低报错等级,在php.ini中设置error_reporting = E_ERROR或者直接在php中设置error_reporting(E_Error);
ThinkPHP解决这个就算了吧,TP本身就没处理这些问题,要处理那么使用的时候都得先通过isset验证一下...
判读这两个变量是否有值,如果有就赋值,没有就为空,按照这个试试