ClientIpResolver
in package
Table of Contents
- $trustedProxies : array<string|int, mixed>
- __construct() : mixed
- getClientIp() : string
- Resolve the original client IP in a proxy-aware, spoof-resistant way.
- setProxies() : self
- cidrMatch() : bool
- Constant-time CIDR match for both IPv4 and IPv6.
- ipInList() : bool
- Does $ip fall inside any of the supplied CIDRs?
- isValidPublicIp() : bool
- Is the IP syntactically valid *and* publicly routable?
Properties
$trustedProxies
private
array<string|int, mixed>
$trustedProxies
Methods
__construct()
public
__construct([array<string|int, string> $trustedProxies = [] ]) : mixed
Parameters
- $trustedProxies : array<string|int, string> = []
-
CIDR notation (e.g. '173.245.48.0/20')
Return values
mixed —getClientIp()
Resolve the original client IP in a proxy-aware, spoof-resistant way.
public
getClientIp(ServerRequestInterface $request) : string
Parameters
- $request : ServerRequestInterface
Return values
string —IPv4/IPv6 literal, or '0.0.0.0' on failure
setProxies()
public
setProxies(array<string|int, string> $trustedProxies) : self
Parameters
- $trustedProxies : array<string|int, string>
-
CIDR notation (e.g. '173.245.48.0/20')
Return values
self —cidrMatch()
Constant-time CIDR match for both IPv4 and IPv6.
private
cidrMatch(string $ip, string $subnet, int $maskBits) : bool
Parameters
- $ip : string
- $subnet : string
- $maskBits : int
Return values
bool —ipInList()
Does $ip fall inside any of the supplied CIDRs?
private
ipInList(string $ip, array<string|int, mixed> $cidrs) : bool
Parameters
- $ip : string
- $cidrs : array<string|int, mixed>
Return values
bool —isValidPublicIp()
Is the IP syntactically valid *and* publicly routable?
private
isValidPublicIp(string|null $ip) : bool
Parameters
- $ip : string|null