IP and IPs, two variables are reported undefined:
Notic: [8] Undefined Variable:ip
Notic: [8] Undefined Variable:ips
Who can help to change the ~ ~
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; } }
Reply content:
IP and IPs, two variables are reported undefined:
Notic: [8] Undefined Variable:ip
Notic: [8] Undefined Variable:ips
Who can help to change the ~ ~
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; } }
If you just want to ignore this problem, lower the error level, set error_reporting = E_error in php.ini, or set it directly in PHPerror_reporting(E_Error);
thinkphp solve this just forget it, TP itself did not deal with these problems, to deal with the use of the time will have to first through the Isset verification ...
The two variables are evaluated for value, and if there is an assignment, none is empty, follow this test