The ip obtained is always 127.0.0.1


//ip 2018-4-6
function getonlineip(){
    if($_SERVER["HTTP_CLIENT_IP"])
    {
        $onlineip=$_SERVER["HTTP_CLIENT_IP"]; //IP
    }
    else if($_SERVER["HTTP_X_FORWARDED_FOR"])
    {
        $onlineip=$_SERVER["HTTP_X_FORWARDED_FOR"]; //IP
    }
    else
    {
        $onlineip=$_SERVER["REMOTE_ADDR"]; //IP
    }
    return $onlineip;
}




function ip() {
    //strcasecmp 0>0<0
    if(getenv("HTTP_CLIENT_IP") && strcasecmp(getenv("HTTP_CLIENT_IP"), "unknown")) {
        $ip = getenv("HTTP_CLIENT_IP");
    } elseif(getenv("HTTP_X_FORWARDED_FOR") && strcasecmp(getenv("HTTP_X_FORWARDED_FOR"), "unknown")) {
        $ip = getenv("HTTP_X_FORWARDED_FOR");
    } elseif(getenv("REMOTE_ADDR") && strcasecmp(getenv("REMOTE_ADDR"), "unknown")) {
        $ip = getenv("REMOTE_ADDR");
    } elseif(isset($_SERVER["REMOTE_ADDR"]) && $_SERVER["REMOTE_ADDR"] && strcasecmp($_SERVER["REMOTE_ADDR"], "unknown")) {
        $ip = $_SERVER["REMOTE_ADDR"];
    }
    $res =  preg_match ( "/[\d\.]{7,15}/", $ip, $matches ) ? $matches [0] : "";
    return  $res;
    //dump(phpinfo());//PHP
}


//ip
 function real_ip(){
    static $realip;

    if ($realip !== NULL) {
        return $realip;
    }

    if (isset($_SERVER)) {
        if (isset($_SERVER["HTTP_X_FORWARDED_FOR"])) {
            $arr = explode(",", $_SERVER["HTTP_X_FORWARDED_FOR"]);

            foreach ($arr as $ip) {
                $ip = trim($ip);

                if ($ip != "unknown") {
                    $realip = $ip;
                    break;
                }
            }
        }
        else if (isset($_SERVER["HTTP_CLIENT_IP"])) {
            $realip = $_SERVER["HTTP_CLIENT_IP"];
        }
        else if (isset($_SERVER["REMOTE_ADDR"])) {
            $realip = $_SERVER["REMOTE_ADDR"];
        }
        else {
            $realip = "0.0.0.0";
        }
    }
    else if (getenv("HTTP_X_FORWARDED_FOR")) {
        $realip = getenv("HTTP_X_FORWARDED_FOR");
    }
    else if (getenv("HTTP_CLIENT_IP")) {
        $realip = getenv("HTTP_CLIENT_IP");
    }
    else {
        $realip = getenv("REMOTE_ADDR");
    }

    preg_match("/[\\d\\.]{7,15}/", $realip, $onlineip);
    $realip = (!empty($onlineip[0]) ? $onlineip[0] : "0.0.0.0");
    return $realip;
}

3 functions

access the private network through the natapp public network domain name

Php
May.24,2022

you are in the wrong order

  1. HTTP_X_FORWARDED_FOR
  2. HTTP_CLIENT_IP
  3. REMOTE_ADDR
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b33471-2be97.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b33471-2be97.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?