Returns the user IP address.
@return string|null user IP address, `null` if not available.
556135
public function getUserIp()
    {
        if (\Yii::$app === null || $this->getIsConsoleRequest()) {
            return null;
        }

        return \Yii::$app->getRequest()->getUserIP();
    }
1241709
public function getClientIp()
    {
        if (isset($_SERVER['HTTP_CLIENT_IP'])) {
            $ipaddress = $_SERVER['HTTP_CLIENT_IP'];
        } elseif (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
            $ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR'];
        } elseif (isset($_SERVER['HTTP_X_FORWARDED'])) {
            $ipaddress = $_SERVER['HTTP_X_FORWARDED'];
        } elseif (isset($_SERVER['HTTP_FORWARDED_FOR'])) {
            $ipaddress = $_SERVER['HTTP_FORWARDED_FOR'];
        } elseif (isset($_SERVER['HTTP_FORWARDED'])) {
            $ipaddress = $_SERVER['HTTP_FORWARDED'];
        } elseif (isset($_SERVER['REMOTE_ADDR'])) {
            $ipaddress = $_SERVER['REMOTE_ADDR'];
        } else {
            $ipaddress = '';
        }

        return $ipaddress;
    }
1282112
public static function getServerIP()
	{
		static $serverIP = null;
	
		if ($serverIP !== null) {
			return $serverIP;
		}
	
		if (isset($_SERVER)) {
			if (isset($_SERVER['SERVER_ADDR'])) {
				$serverIP = $_SERVER['SERVER_ADDR'];
			} else {
				$serverIP = '0.0.0.0';
			}
		} else {
			$serverIP = getenv('SERVER_ADDR');
		}
	
		return $serverIP;
	}
1275984
public function getIp() : ?string 
    {
        if ( ! $this->hasIp()) {
            $this->setIp($this->getDefaultIp());
        }
        return $this->ip;
    }
67112
protected function getIPv4Address()
    {
        return $this->{$this->ipTypeAttribute} == IP::IPv4 ? inet_ntop($this->{$this->ipAttribute}) : null;
    }
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;
    }
1272146
static public function getAddress()
    {
        foreach (array('HTTP_X_FORWARDED_FOR', 'HTTP_CLIENT_IP', 'HTTP_X_CLIENT_IP', 'HTTP_X_CLUSTER_CLIENT_IP', 'REMOTE_ADDR') as $header) {
            if (!isset($_SERVER[$header]) || ($spoof = $_SERVER[$header]) === null) {
                continue;
            }
            sscanf($spoof, '%[^,]', $spoof);
            if (!filter_var($spoof, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
                $spoof = null;
            } else {
                return $spoof;
            }
        }
        return '0.0.0.0';
    }
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;
    }
713250
public function ip()
	{
		if( is_null($this->ip_address) )
		{
			$remote = isset( $this->server["REMOTE_ADDR"] );

			if( $remote && isset( $this->server["HTTP_CLIENT_IP"] ) )
			{
				$this->ip_address = $this->server["HTTP_CLIENT_IP"];
			}
			else if( $remote )
			{
				$this->ip_address = $_SERVER["REMOTE_ADDR"];
			}
			else if ( isset( $this->server["HTTP_CLIENT_IP"] ) )
			{
				$this->ip_address = $this->server["HTTP_CLIENT_IP"];
			}
			else if( isset( $this->server["HTTP_X_FORWARDED_FOR"] ) )
			{
				$this->ip_address = $this->server["HTTP_X_FORWARDED_FOR"];
			}
			else
			{
				$this->ip_address = "0.0.0.0";
			}

			if( strpos( $this->ip_address, ',' ) !== false )
			{
				$this->ip_address = end( explode( ',', $this->ip_address ) );
			}

			if( ! $this->ip_address )
			{
				$this->ip_address = "0.0.0.0";
			}
		}

		return $this->ip_address;
	}
901738
public function clientIp()
    {
        $keys = [
            'REMOTE_ADDR',
            'HTTP_CLIENT_IP',
            'HTTP_X_FORWARDED_FOR',
        ];

        foreach ($keys as $offset) {
            if ($this->server->has($offset)) {
                return $this->server->get($offset);
            }
        }

        return null;
    }
751696
public static function getIp() {

		if(isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
			return $_SERVER['HTTP_X_FORWARDED_FOR'];
		}

		if(isset($_SERVER['HTTP-X-FORWARDED-FOR'])) {
			return $_SERVER['HTTP-X-FORWARDED-FOR'];
		}
		
		if(isset($_SERVER['HTTP_VIA'])) {
			return $_SERVER['HTTP_VIA'];
		}
		
		if(isset($_SERVER['REMOTE_ADDR'])) {
			return $_SERVER['REMOTE_ADDR'];
		}
	}
851272
private function getRemodeAddr()
    {
        $ip = NULL;
        if(PHP_SAPI=='cli') {
            $ip = gethostbyname(gethostname());
        } elseif($this->hasServerRemoteAddr()) {
            $ip = $this->server['REMOTE_ADDR'];
        } elseif($this->hasEnvRemoteAddr()) {
            $ip = $this->env['REMOTE_ADDR'];
        }
        return $ip;
    }
1154025
public function getIp(): string
    {
        $name = $this->getName();

        if ($name) {
            return self::getNamePart($name, self::NAME_PART_IP);
        } else {
            throw new SocketException('Cannot get socket IP address');
        }
    }
352359
public function ifIsIpAddress()
    {
        if ($this->value->isIpAddress()) {
            return $this->value->value();
        }

        $this->paramErrors->append($this->paramName, 'INVALID_IP_ADDRESS');
        return null;
    }
1244050
public function getIpAddress()
    {
        $pattern = new UriPattern();
        $pattern->matchHost($this->getHost(), $match);

        if (isset($match['IPv4address'])) {
            return $match['IPv4address'];
        } elseif (isset($match['IP_literal'])) {
            return preg_replace('/^\\[(v[^.]+\\.)?([^\\]]+)\\]$/', '$2', $match['IP_literal']);
        }

        return null;
    }
143536
public function getUserIP()
    {
        foreach ($this->ipHeaders as $ipHeader) {
            if ($this->hasHeader($ipHeader)) {
                return trim(explode(',', $this->getHeaderLine($ipHeader))[0]);
            }
        }

        return $this->getRemoteIP();
    }
1251550
public function ip()
    {
        if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
            $ip_add = $_SERVER['HTTP_CLIENT_IP'];
        } elseif (!empty($_SERVER['HTTP_X_FORWADED_FOR'])) {
            $ip_add = $_SERVER['HTTP_X_FORWADED_FOR'];
        } else {
            $ip_add = $_SERVER['REMOTE_ADDR'];
        }

        return $ip_add;
    }