Piwik\

IP

Contains IP address helper functions (for both IPv4 and IPv6).

As of Matomo (formerly Piwik) 2.9, most methods in this class are deprecated. You are encouraged to use classes from the Matomo "Network" component:

Methods

The class defines the following methods:

getIpFromHeader()

Returns the most accurate IP address available for the current user, in IPv4 format.

This could be the proxy client's IP address.

Signature

  • Returns: string — IP address in presentation format.

getNonProxyIpFromHeader()

Returns a non-proxy IP address from header.

Signature

  • It accepts the following parameter(s):
    • $default (string) — Default value to return if there no matching proxy header.
    • $proxyHeaders (array) — List of proxy headers.
  • It returns a string value.

getFirstIpFromList()

Returns the last IP address in a comma separated list, subject to an optional exclusion list.

Signature

  • It accepts the following parameter(s):

    • $csv (string) — Comma separated list of elements.
    • $excludedIps (array) — Optional list of excluded IP addresses (or IP address ranges).
  • Returns: string — Last (non-excluded) IP address in the list or an empty string if all given IPs are excluded.