获取客户端IP
@return string|unknown
433897
public static function getClientIp()
    {
        if (getenv("HTTP_CLIENT_IP")){
            $ip = getenv("HTTP_CLIENT_IP");
        }
        else if (getenv("HTTP_X_FORWARDED_FOR")){
            $ip = getenv("HTTP_X_FORWARDED_FOR");
        }
        else if (getenv("HTTP_X_FORWARDED")){
            $ip = getenv("HTTP_X_FORWARDED");
        }
        else if (getenv("HTTP_FORWARDED_FOR")){
            $ip = getenv("HTTP_FORWARDED_FOR");
        }
        else if (getenv("HTTP_FORWARDED")){
            $ip = getenv("HTTP_FORWARDED");
        }
        else{
            $ip = $_SERVER["REMOTE_ADDR"];
        }
        return $ip;
    }
1196918
public function visitorGetUserIP()
	{
	    $UserIP = \Environment::get('ip');
	    if (strpos($UserIP, ',') !== false) //first IP
	    {
	        $UserIP = trim( substr($UserIP, 0, strpos($UserIP, ',') ) );
	    }
	    if ( true === $this->visitorIsPrivateIP($UserIP) &&
	        false === empty($_SERVER['HTTP_X_FORWARDED_FOR'])
	        )
	    {
	        //second try
	        $HTTPXFF = $_SERVER['HTTP_X_FORWARDED_FOR'];
	        $_SERVER['HTTP_X_FORWARDED_FOR'] = '';
	
	        $UserIP = \Environment::get('ip');
	        if (strpos($UserIP, ',') !== false) //first IP
	        {
	            $UserIP = trim( substr($UserIP, 0, strpos($UserIP, ',') ) );
	        }
	        $_SERVER['HTTP_X_FORWARDED_FOR'] = $HTTPXFF;
	    }
	    return $UserIP;
	}
759045
public function getClientIp(){

        if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])){
            // Use the forwarded IP address, typically set when the
            // client is using a proxy server.
            return $_SERVER['HTTP_X_FORWARDED_FOR'];
        }elseif (isset($_SERVER['HTTP_CLIENT_IP'])){
            // Use the forwarded IP address, typically set when the
            // client is using a proxy server.
            return $_SERVER['HTTP_CLIENT_IP'];
        }
        elseif (isset($_SERVER['REMOTE_ADDR'])){
            // The remote IP address
            return $_SERVER['REMOTE_ADDR'];
        }

        return null;
    }
1154914
public function getIp()
    {
        $keys = ['X_FORWARDED_FOR', 'HTTP_X_FORWARDED_FOR', 'CLIENT_IP', 'REMOTE_ADDR'];

        foreach ($keys as $key) {
            $ip = $this->getServerParam($key);

            if (!$ip) {
                continue;
            }

            $ip = preg_replace('/,.*$/u', '', $ip);
            $ip = trim($ip);

            return $ip;
        }

        return null;
    }
776132
public function GetClientIp () {
		if ($this->clientIp === NULL) {
			$this->clientIp = (isset($this->globalServer['REMOTE_ADDR'])
				? $this->globalServer['REMOTE_ADDR']
				: (isset($this->globalServer['HTTP_X_CLIENT_IP'])
					? $this->globalServer['HTTP_X_CLIENT_IP']
					: ''));
			$this->clientIp = preg_replace("#[^0-9a-zA-Z\.\:\[\]]#", '', $this->clientIp);
		}
		return $this->clientIp;
	}
638904
protected function _getIp()
    {
        if (!$this->_request()) {
            return null;
        }
        $ip = $this->_request()->getClientIp();

        if ($this->_isValidIpv4($ip)) {
            return $ip;
        }

        // sometimes the value is multiple IPs separated by commas
        // (when there are multiple proxies, for example)
        $ips = explode(',', $ip, 2);
        $ip = trim($ips[0]);
        if ($this->_isValidIpv4($ip)) {
            return $ip;
        }

        return null;
    }
135160
private function getCustomerIP()
    {
        $ip = null;
        if(array_key_exists('X-Forwarded-For', $_SERVER)) {
            $ip = $_SERVER['X-Forwarded-For'];
        } elseif(array_key_exists('HTTP_X_FORWARDED_FOR', $_SERVER)) {
            $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
        } elseif(array_key_exists('REMOTE_ADDR', $_SERVER)) {
            $ip = $_SERVER['REMOTE_ADDR'];
        }

        return $ip;
    }
47474
public static function findIp() {
		if ((int)Configure::read('debug') > 1) {
			$ip = Configure::read('App.defaultIp');
			if ($ip) {
				return $ip;
			}
			return '127.0.0.1';
		}
		$ip = Utility::getClientIp();
		# usually getClientIp already removes multiple ips in favor of one single ip. but seems to fail sometimes
		if (strpos($ip, ',') !== false) {
			return false;
			//$ips = explode(',', $ip);
			//$ip = trim($ips[0]); # first
			//$ip = trim($ips[count($ips)-1]); # last
		}
		return $ip;
	}
423749
protected function getRequestIp()
    {
        if (isset($this->server['HTTP_X_FORWARDED_FOR'])) {
            return $this->server['HTTP_X_FORWARDED_FOR'];
        }

        if (isset($this->server['REMOTE_ADDR'])) {
            return $this->server['REMOTE_ADDR'];
        }
    }
363759
public static function serverIP(): string
    {
        if (!empty($_SERVER['SERVER_ADDR'])) {
            $ip = $_SERVER['SERVER_ADDR'];
        } elseif (!empty($_SERVER['SERVER_NAME'])) {
            $ip = gethostbyname($_SERVER['SERVER_NAME']);
        } else {
            // for php-cli(phpunit etc.)
            $ip = defined('PHPUNIT_RUNNING')
                ? '127.0.0.1'
                : gethostbyname(gethostname());
        }
        return filter_var($ip, FILTER_VALIDATE_IP) ?: '127.0.0.1';
    }
789340
public static function ip(): string
    {
        if (static::$realIp !== null) {
            return static::$realIp;
        }

        $possibilities = [
          'HTTP_CLIENT_IP',
          'HTTP_X_FORWARDED_FOR',
          'HTTP_X_FORWARDED',
          'HTTP_X_CLUSTER_CLIENT_IP',
          'HTTP_FORWARDED_FOR',
          'HTTP_FORWARDED',
          'REMOTE_ADDR'
        ];

        foreach ($possibilities as $key) {
            if (isset($_SERVER[$key])) {
                foreach (explode(',', $_SERVER[$key]) as $ip) {
                    $ip = trim($ip);

                    if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE) !== false) {
                        static::$realIp = $ip;
                        return $ip;
                    }
                }
            }
        }

        if (KOLDY_CLI) {
            static::$realIp = '127.0.0.1';
        } else if (isset($_SERVER['REMOTE_ADDR'])) {
            static::$realIp = $_SERVER['REMOTE_ADDR'];
        } else {
            throw new Exception('Unable to detect IP');
        }

        return static::$realIp;
    }
703067
public function get_callback_ip(){
        $access_token = $this->get_access_token();
        if (!$access_token){
            if ($this->business_interface) $this->business_interface->log('access_token is null');
            return null;
        }
        $url = self::API_CALLBACK_IP.'access_token='.$access_token;
        $result = $this->curl($url);
        return $result;
    }
1348897
public function getIp(): string
    {
        if ($this->ip === null) {
            foreach (["HTTP_X_FORWARDED_FOR", "X_FORWARDED_FOR"] as $key) {
                $proxyIpList = $this->environment[$key] ?? "";
                if ($proxyIpList) {
                    $commaPosition = strpos($proxyIpList, ",");
                    if ($commaPosition !== false) {
                        $this->ip = substr($proxyIpList, 0, $commaPosition);
                    } else {
                        $this->ip = $proxyIpList;
                    }
                    return $this->ip;
                }
            }
            $this->ip = $this->environment["REMOTE_ADDR"] ?? "";
        }
        return $this->ip;
    }
852478
public function getIp(){
		if( (int) $this->lastCheck > 0 && time() - $this->lastCheck < 10 * 60 )
			return $this->lastIp;
		$this->reader->setUrl( 'http://checkip.dyndns.org' );
		$html	= $this->reader->read();
		$parts	= explode( ": ", strip_tags( $html ) );
		$ip		= trim( array_pop( $parts ) );
		$this->save( array( 'ip' => $ip, 'timestamp' => time() ) );
		return $ip;
	}
840605
public static function IP(){
   switch(true){
     case !empty($_SERVER['HTTP_X_FORWARDED_FOR']):
       $ip = trim(substr(strrchr($_SERVER['HTTP_X_FORWARDED_FOR'],','),1) ?: $_SERVER['HTTP_X_FORWARDED_FOR']);
     break;
     case !empty($_SERVER['HTTP_X_FORWARDED_HOST']):
       $ip = trim(substr(strrchr($_SERVER['HTTP_X_FORWARDED_HOST'],','),1) ?: $_SERVER['HTTP_X_FORWARDED_HOST']);
     break;
     case !empty($_SERVER['REMOTE_ADDR']):    $ip = $_SERVER['REMOTE_ADDR']; break;
     case !empty($_SERVER['HTTP_CLIENT_IP']): $ip = $_SERVER['HTTP_CLIENT_IP']; break;
     default:                                 $ip = ''; break;
   }
   return Filter::with('core.request.IP',$ip);
  }
357600
public function getRequestIp()
    {
        $headers = [
            'HTTP_CLIENT_IP',
            'HTTP_X_FORWARDED_FOR',
            'HTTP_X_FORWARDED',
            'HTTP_FORWARDED_FOR',
            'HTTP_FORWARDED',
            'REMOTE_ADDR',
        ];
        foreach ($headers as $header) {
            if ($this->server($header) !== false) {
                return $this->server($header);
            }
        }

        return 'UNKNOWN';
    }
646778
public function ip()
    {
        if (isset($_SERVER["HTTP_CLIENT_IP"])) {
            $ip = $_SERVER["HTTP_CLIENT_IP"];
        } elseif (isset($_SERVER["HTTP_X_FORWARDED_FOR"])) {
            $ip = $_SERVER["HTTP_X_FORWARDED_FOR"];
        } elseif (isset($_SERVER["HTTP_X_FORWARDED"])) {
            $ip = $_SERVER["HTTP_X_FORWARDED"];
        } elseif (isset($_SERVER["HTTP_FORWARDED_FOR"])) {
            $ip = $_SERVER["HTTP_FORWARDED_FOR"];
        } elseif (isset($_SERVER["HTTP_FORWARDED"])) {
            $ip = $_SERVER["HTTP_FORWARDED"];
        } elseif (isset($_SERVER["REMOTE_ADDR"])) {
            $ip = $_SERVER["REMOTE_ADDR"];
        } else {
            $ip = getenv("REMOTE_ADDR");
        }
        
        if(strpos($ip, ',') !== false){
            $ip = explode(',', $ip)[0];
        }

        if (!filter_var($ip, FILTER_VALIDATE_IP)) {
            return 'unknown';
        }

        return $ip;
    }