PHP Class FOF30\Utils\Ip

Makes sure that we get the real IP of the user
Datei anzeigen Open project: akeeba/fof Class Usage Examples

Protected Properties

Property Type Description
$allowIpOverrides boolean Should I allow IP overrides through X-Forwarded-For or Client-Ip HTTP headers?
$ip string The IP address of the current visitor

Public Methods

Method Description
IPinList ( string $ip, array | string $ipTable = '' ) : null | boolean Checks if an IP is contained in a list of IPs or IP expressions
getIp ( ) : string Get the current visitor's IP address
setAllowIpOverrides ( boolean $newState ) : void Should I allow the remote client's IP to be overridden by an X-Forwarded-For or Client-Ip HTTP header?
setIp ( string $ip ) : void Set the IP address of the current visitor
workaroundIPIssues ( ) Works around the REMOTE_ADDR not containing the user's IP

Protected Methods

Method Description
checkIPv6CIDR ( string $ip, string $cidrnet ) : boolean Checks if an IPv6 address $ip is part of the IPv6 CIDR block $cidrnet
detectAndCleanIP ( ) : string Gets the visitor's IP address. Automatically handles reverse proxies reporting the IPs of intermediate devices, like load balancers. Examples: https://www.akeebabackup.com/support/admin-tools/13743-double-ip-adresses-in-security-exception-log-warnings.html http://stackoverflow.com/questions/2422395/why-is-request-envremote-addr-returning-two-ips The solution used is assuming that the last IP address is the external one.
detectIP ( ) : string Gets the visitor's IP address
inet_to_bits ( string $inet ) : string Converts inet_pton output to bits string
isIPv6 ( string $ip ) : boolean Is it an IPv6 IP address?

Method Details

IPinList() public static method

Checks if an IP is contained in a list of IPs or IP expressions
public static IPinList ( string $ip, array | string $ipTable = '' ) : null | boolean
$ip string The IPv4/IPv6 address to check
$ipTable array | string An IP expression (or a comma-separated or array list of IP expressions) to check against
return null | boolean True if it's in the list

checkIPv6CIDR() protected static method

Checks if an IPv6 address $ip is part of the IPv6 CIDR block $cidrnet
protected static checkIPv6CIDR ( string $ip, string $cidrnet ) : boolean
$ip string The IPv6 address to check, e.g. 21DA:00D3:0000:2F3B:02AC:00FF:FE28:9C5A
$cidrnet string The IPv6 CIDR block, e.g. 21DA:00D3:0000:2F3B::/64
return boolean

detectAndCleanIP() protected static method

Gets the visitor's IP address. Automatically handles reverse proxies reporting the IPs of intermediate devices, like load balancers. Examples: https://www.akeebabackup.com/support/admin-tools/13743-double-ip-adresses-in-security-exception-log-warnings.html http://stackoverflow.com/questions/2422395/why-is-request-envremote-addr-returning-two-ips The solution used is assuming that the last IP address is the external one.
protected static detectAndCleanIP ( ) : string
return string

detectIP() protected static method

Gets the visitor's IP address
protected static detectIP ( ) : string
return string

getIp() public static method

Get the current visitor's IP address
public static getIp ( ) : string
return string

inet_to_bits() protected static method

Converts inet_pton output to bits string
protected static inet_to_bits ( string $inet ) : string
$inet string The in_addr representation of an IPv4 or IPv6 address
return string

isIPv6() protected static method

Is it an IPv6 IP address?
protected static isIPv6 ( string $ip ) : boolean
$ip string An IPv4 or IPv6 address
return boolean True if it's IPv6

setAllowIpOverrides() public static method

Should I allow the remote client's IP to be overridden by an X-Forwarded-For or Client-Ip HTTP header?
public static setAllowIpOverrides ( boolean $newState ) : void
$newState boolean True to allow the override
return void

setIp() public static method

Set the IP address of the current visitor
public static setIp ( string $ip ) : void
$ip string
return void

workaroundIPIssues() public static method

Works around the REMOTE_ADDR not containing the user's IP
public static workaroundIPIssues ( )

Property Details

$allowIpOverrides protected_oe static_oe property

Should I allow IP overrides through X-Forwarded-For or Client-Ip HTTP headers?
protected static bool $allowIpOverrides
return boolean

$ip protected_oe static_oe property

The IP address of the current visitor
protected static string $ip
return string