IpHelper

IpHelper is a utility class for processing IP addresses

final
since

1.6.0

Methods

__construct

Private constructor to prevent instantiation of this class

__construct() 
since

1.6.0

checkIPv6CIDR

Checks if an IPv6 address $ip is part of the IPv6 CIDR block $cidrnet

checkIPv6CIDR(string $ip, string $cidrnet) : boolean
static
since

1.6.0

Arguments

$ip

stringThe IPv6 address to check, e.g. 21DA:00D3:0000:2F3B:02AC:00FF:FE28:9C5A

$cidrnet

stringThe IPv6 CIDR block, e.g. 21DA:00D3:0000:2F3B::/64

Response

boolean

detectAndCleanIP

Gets the visitor's IP address.

detectAndCleanIP() : string
static

Automatically handles reverse proxies reporting the IPs of intermediate devices, like load balancers. Examples:

The solution used is assuming that the last IP address is the external one.

since

1.6.0

Response

string

detectIP

Gets the visitor's IP address

detectIP() : string
static
since

1.6.0

Response

string

getIp

Get the current visitor's IP address

getIp() : string
static
since

1.6.0

Response

string

inetToBits

Converts inet_pton output to bits string

inetToBits(string $inet) : string
static
since

1.6.0

Arguments

$inet

stringThe in_addr representation of an IPv4 or IPv6 address

Response

string

IPinList

Checks if an IP is contained in a list of IPs or IP expressions

IPinList(string $ip, array|string $ipTable = '') : boolean
static
since

1.6.0

Arguments

$ip

stringThe IPv4/IPv6 address to check

$ipTable

array|stringAn IP expression (or a comma-separated or array list of IP expressions) to check against

Response

boolean

isIPv6

Is it an IPv6 IP address?

isIPv6(string $ip) : boolean
static
since

1.6.0

Arguments

$ip

stringAn IPv4 or IPv6 address

Response

boolean

setAllowIpOverrides

Should I allow the remote client's IP to be overridden by an X-Forwarded-For or Client-Ip HTTP header?

setAllowIpOverrides(boolean $newState) : void
static
since

1.6.0

Arguments

$newState

booleanTrue to allow the override

setIp

Set the IP address of the current visitor

setIp(string $ip) : void
static
since

1.6.0

Arguments

$ip

stringThe visitor's IP address

workaroundIPIssues

Works around the REMOTE_ADDR not containing the user's IP

workaroundIPIssues() : void
static
since

1.6.0

Properties

ip

The IP address of the current visitor

static
since

1.6.0

Type(s)

string

allowIpOverrides

Should I allow IP overrides through X-Forwarded-For or Client-Ip HTTP headers?

static
since

1.6.0

note

The default value is false in version 2.0+

Type(s)

boolean