public function current(): string
    {
        if (($ip = &$this->cacheKey(__FUNCTION__)) !== null) {
            return $ip; // Already cached this.
        }
        if ($this->c::isCli()) {
            throw $this->c::issue('Not possible in CLI mode.');
        } // @TODO Try detecting IP address in CLI mode.

        $sources = [
            'HTTP_CF_CONNECTING_IP',
            'HTTP_CLIENT_IP',
            'HTTP_X_FORWARDED_FOR',
            'HTTP_X_FORWARDED',
            'HTTP_X_CLUSTER_CLIENT_IP',
            'HTTP_FORWARDED_FOR',
            'HTTP_FORWARDED',
            'HTTP_VIA',
            'REMOTE_ADDR',
        ];
        foreach ($sources as $_source) {
            if (!empty($_SERVER[$_source]) && is_string($_SERVER[$_source])) {
                if (($_valid_public_ip = $this->getValidPublicFrom($_SERVER[$_source]))) {
                    return $ip = $_valid_public_ip; // IPv4 or IPv6 address.
                }
            } // unset($_valid_public_ip); // Housekeeping.
        } // unset($_source); // Housekeeping.

        if (!empty($_SERVER['REMOTE_ADDR'])) {
            return $ip = mb_strtolower((string) $_SERVER['REMOTE_ADDR']);
        }
        return $ip = 'unknown'; // Not possible.
    }
public function current(): string
    {
        if (($ip = &$this->cacheKey(__FUNCTION__)) !== null) {
            return $ip; // Already cached this.
        }
        if ($this->c::isCli()) {
            throw $this->c::issue('Not possible in CLI mode.');
        } // @TODO Try detecting IP address in CLI mode.

        $sources = [
            'HTTP_CF_CONNECTING_IP',
            'HTTP_CLIENT_IP',
            'HTTP_X_FORWARDED_FOR',
            'HTTP_X_FORWARDED',
            'HTTP_X_CLUSTER_CLIENT_IP',
            'HTTP_FORWARDED_FOR',
            'HTTP_FORWARDED',
            'HTTP_VIA',
            'REMOTE_ADDR',
        ];
        foreach ($sources as $_source) {
            if (!empty($_SERVER[$_source]) && is_string($_SERVER[$_source])) {
                if (($_valid_public_ip = $this->getValidPublicFrom($_SERVER[$_source]))) {
                    return $ip = $_valid_public_ip; // IPv4 or IPv6 address.
                }
            } // unset($_valid_public_ip); // Housekeeping.
        } // unset($_source); // Housekeeping.

        if (!empty($_SERVER['REMOTE_ADDR'])) {
            return $ip = mb_strtolower((string) $_SERVER['REMOTE_ADDR']);
        }
        return $ip = 'unknown'; // Not possible.
    }
public function current ( ) : string { if ( ( $ ip = & $ this -> cacheKey ( __FUNCTION__ ) ) !== null ) { return $ ip ; // Already cached this. } if ( $ this -> c :: isCli ( ) ) { throw $ this -> c :: issue ( 'Not possible in CLI mode.' ) ; } // @TODO Try detecting IP address in CLI mode. $ sources = [ 'HTTP_CF_CONNECTING_IP' , 'HTTP_CLIENT_IP' , 'HTTP_X_FORWARDED_FOR' , 'HTTP_X_FORWARDED' , 'HTTP_X_CLUSTER_CLIENT_IP' , 'HTTP_FORWARDED_FOR' , 'HTTP_FORWARDED' , 'HTTP_VIA' , 'REMOTE_ADDR' , ] ; foreach ( $ sources as $ _source ) { if ( ! empty ( $ _SERVER [ $ _source ] ) && is_string ( $ _SERVER [ $ _source ] ) ) { if ( ( $ _valid_public_ip = $ this -> getValidPublicFrom ( $ _SERVER [ $ _source ] ) ) ) { return $ ip = $ _valid_public_ip ; // IPv4 or IPv6 address. } } // unset($_valid_public_ip); // Housekeeping. } // unset($_source); // Housekeeping. if ( ! empty ( $ _SERVER [ 'REMOTE_ADDR' ] ) ) { return $ ip = mb_strtolower ( ( string ) $ _SERVER [ 'REMOTE_ADDR' ] ) ; } return $ ip = 'unknown' ; // Not possible. }
Current visitor's IP address.

@since 150424 Initial release.

@return string Current visitor's IP address.

@internal Supports both IPv4 & IPv6 addresses.
Current visitor s IP address .