thinkphp 3.2.3 How to solve the ' Undefined variable ' this error?

Source: Internet
Author: User
Keywords thinkphp php
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

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.