Returns the first valid proxied IP found.

@return string|null
498729
private function getProxiedIp(ServerRequestInterface $request)
    {
        foreach ($this->proxyHeaders as $name) {
            if ($request->hasHeader($name)) {
                if (substr($name, -9) === 'Forwarded') {
                    $ip = $this->getForwardedHeaderIp($request->getHeaderLine($name));
                } else {
                    $ip = $this->getHeaderIp($request->getHeaderLine($name));
                }

                if ($ip !== null) {
                    return $ip;
                }
            }
        }
    }
198878
public function getIpAdress()
    {
        $ip_keys = ['HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', 'HTTP_X_FORWARDED', 'HTTP_X_CLUSTER_CLIENT_IP', 'HTTP_FORWARDED_FOR', 'HTTP_FORWARDED', 'REMOTE_ADDR'];
        foreach ($ip_keys as $key) {
            if (array_key_exists($key, $_SERVER) === true) {
                foreach (explode(',', $_SERVER[$key]) as $ip) {
                    $ip = trim($ip);
                    if ($this->validateIp($ip)) {
                        return $ip;
                    }
                }
            }
        }

        return isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : false;
    }
771806
public static function getClientIp()
    {
        //Just get the headers if we can or else use the SERVER global
        if (function_exists('apache_request_headers')) {
            $headers = apache_request_headers();
        } else {
            $headers = $_SERVER;
        }
        //Get the forwarded IP if it exists
        if (array_key_exists('X-Forwarded-For', $headers) &&
            filter_var($headers['X-Forwarded-For'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
            $the_ip = $headers['X-Forwarded-For'];
        } else {
            if (array_key_exists('HTTP_X_FORWARDED_FOR', $headers) &&
                filter_var($headers['HTTP_X_FORWARDED_FOR'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
                $the_ip = $headers['HTTP_X_FORWARDED_FOR'];
            } else {
                if (array_key_exists('X-ClientSide', $headers)) {
                    $parts  = explode(':', $headers['X-ClientSide']);
                    $the_ip = $parts[0];
                } else {
                    $the_ip = filter_var($_SERVER['REMOTE_ADDR'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4);
                }
            }
        }
        return $the_ip;
    }
305548
protected function getUserIp()
    {
        if (!isset($_SERVER) || $this->captureIP === false) {
            return null;
        }
        
        $ipAddress = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : null;
        
        $forwardFor = isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : null;
        if ($forwardFor) {
            // return everything until the first comma
            $parts = explode(',', $forwardFor);
            $ipAddress = $parts[0];
        }
        $realIp = isset($_SERVER['HTTP_X_REAL_IP']) ? $_SERVER['HTTP_X_REAL_IP'] : null;
        if ($realIp) {
            $ipAddress = $realIp;
        }
        
        if ($this->captureIP === DataBuilder::ANONYMIZE_IP) {
            if (filter_var($ipAddress, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
                $parts = explode('.', $ipAddress);
                $ipAddress = $parts[0] . '.' . $parts[1] . '.' . $parts[2] . '.0';
            } elseif (filter_var($ipAddress, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
                $parts = explode(':', $ipAddress);
                $ipAddress =
                    $parts[0] . ':' .
                    $parts[1] . ':' .
                    $parts[2] . ':' .
                    '0000:0000:0000:0000:0000';
            }
        }
        
        return $ipAddress;
    }
422765
public static function getClientIp($checkProxy = true)
    {
        $result = null;
        if ($checkProxy) {
            $result = self::getServer('HTTP_CLIENT_IP') ?? self::getServer('HTTP_X_FORWARDED_FOR') ?? null;
        }
        return $result ?? self::getServer('REMOTE_ADDR');
    }
1212659
public function get_proxied_instance() {
        if (!$this->cm) {
            $this->cm = get_fast_modinfo($this->base->course)->instances[$this->base->modname][$this->base->instance];
        }
        return $this->cm;
    }
1339071
private static function getProxyString(): ?string
    {
        $proxyString = null;
        if (\getenv('HTTP_CLIENT_IP')) {
            $proxyString = \getenv('HTTP_CLIENT_IP');
        } elseif (\getenv('HTTP_X_FORWARDED_FOR')) {
            $proxyString = \getenv('HTTP_X_FORWARDED_FOR');
        } elseif (\getenv('HTTP_X_FORWARDED')) {
            $proxyString = \getenv('HTTP_X_FORWARDED');
        } elseif (\getenv('HTTP_X_COMING_FROM')) {
            $proxyString = \getenv('HTTP_X_COMING_FROM');
        } elseif (\getenv('HTTP_FORWARDED_FOR')) {
            $proxyString = \getenv('HTTP_FORWARDED_FOR');
        } elseif (\getenv('HTTP_FORWARDED')) {
            $proxyString = \getenv('HTTP_FORWARDED');
        } elseif (\getenv('HTTP_COMING_FROM')) {
            $proxyString = \getenv('HTTP_COMING_FROM');
        }
        return $proxyString;
    }
439234
public function getRealIPAddress() {
        $ip = null;
        if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
            //check ip from share internet
            $ip = $_SERVER['HTTP_CLIENT_IP'];
        } else if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
            //to check ip is pass from proxy
            $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
        } else {
            $ip = $_SERVER['REMOTE_ADDR'];
        }
        return filter_var($ip, FILTER_VALIDATE_IP);
    }
526545
public static function get_client_ip() {
        $ipaddress = '';
        if (getenv('HTTP_CLIENT_IP')) $ipaddress = getenv('HTTP_CLIENT_IP');
        else if (getenv('HTTP_X_FORWARDED_FOR')) $ipaddress = getenv('HTTP_X_FORWARDED_FOR');
        else if (getenv('HTTP_X_FORWARDED')) $ipaddress = getenv('HTTP_X_FORWARDED');
        else if (getenv('HTTP_FORWARDED_FOR')) $ipaddress = getenv('HTTP_FORWARDED_FOR');
        else if (getenv('HTTP_FORWARDED')) $ipaddress = getenv('HTTP_FORWARDED');
        else if (getenv('REMOTE_ADDR')) $ipaddress = getenv('REMOTE_ADDR');
        else $ipaddress = 'UNKNOWN';
        return $ipaddress;
    }
767595
public static function ip() : string {
		// for development purposes we might need to have specific IP address
		$request_ip = Application::get('flag.numbers.framework.request.ip');
		if (!empty($request_ip)) {
			return $request_ip;
		}
		// get users IP
		$result = $_SERVER['REMOTE_ADDR'];
		// if request goes through the proxy
		if (!empty($_SERVER['HTTP_X_REAL_IP'])) {
			$result = $_SERVER['HTTP_X_REAL_IP'];
		}
		if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
			$result = $_SERVER['HTTP_X_FORWARDED_FOR'];
		}
		// sometimes we have few IP addresses we take last one
		if (strpos($result, ',') !== false) {
			$temp = explode(',', $result);
			$result = trim($temp[sizeof($temp) - 1]);
		}
		// unknown
		if ($result == 'unknown' || is_null($result)) {
			$result = '127.0.0.1';
		}
		return $result;
	}
754276
public function lookup()
    {
        if ($this->ip) {
            $result = $this->lookupIp($this->ip);
        } else {
            $result = $this->lookupDomain($this->domain);
        }
        return $result;
    }
248388
public static function getIp()
	{
		if (self::$ip === null)
		{
			$ip = self::detectAndCleanIP();

			if (!empty($ip) && ($ip != '0.0.0.0') && \function_exists('inet_pton') && \function_exists('inet_ntop'))
			{
				$myIP = @inet_pton($ip);

				if ($myIP !== false)
				{
					$ip = inet_ntop($myIP);
				}
			}

			self::setIp($ip);
		}

		return self::$ip;
	}
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;
    }
752330
public static function getClientIps()
    {
        // Get the list of client IP addresses by first setting the
        // list of trusted proxies.
        // Request::setTrustedProxies(['reverse.proxies.go.here']);
        $clientIps = Request::getClientIps();
        $clientIp  = implode(', ', $clientIps);

        // Also get any addresses in _SERVER["HTTP_X_FORWARDED_FOR"]
        $forwardAddress = isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : '';
        if (empty($clientIp)) {
            $clientIp = $forwardAddress;
        } elseif (! empty($forwardAddress)) {
            $clientIp = $clientIp . ',' . $forwardAddress;
        }

        return $clientIp;
    }
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;
    }
135567
public function getIpAddress()
    {
        foreach ($this->headers as $k)
        {
            if (isset($this->server[$k]))
            {
                // header can be comma separated
                $ips = explode(',', $this->server[$k]);
                $ip = trim(end($ips));
                $ip = filter_var($ip, FILTER_VALIDATE_IP);
                if (false !== $ip)
                {
                    return $ip;
                }
            }
        }

        // no valid ip found
        return false;
    }
593355
public static function _getUserIpAddr ()
    {
        $ip = 'unknown.ip.address';
        if(isset($_SERVER)){
	        if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) // If server is behind a load balancer
			{
	            $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
	        } elseif (!empty($_SERVER['REMOTE_ADDR'])) {
	            $ip = $_SERVER['REMOTE_ADDR'];
	        }
	    }
        return $ip;
    }