DefaultIpResolver
in package
implements
IIpResolver
Default IP resolver implementation that checks common proxy headers.
This resolver checks standard proxy headers in order of preference, validating and extracting the client IP address. It handles:
- Cloudflare (CF-Connecting-IP)
- Standard proxies (X-Forwarded-For)
- Nginx (X-Real-IP)
- Other proxies (Client-IP)
Falls back to REMOTE_ADDR if no valid IP is found in headers.
Table of Contents
Interfaces
- IIpResolver
- Interface for IP address resolution strategies.
Methods
- resolve() : string
- Resolve the client IP address by checking common proxy headers.
- extractFirstIp() : string
- Extract the first IP from a potentially comma-separated list.
Methods
resolve()
Resolve the client IP address by checking common proxy headers.
public
resolve(array<string|int, mixed> $server) : string
Parameters
- $server : array<string|int, mixed>
-
The $_SERVER array
Return values
string —The resolved IP address
extractFirstIp()
Extract the first IP from a potentially comma-separated list.
protected
extractFirstIp(string $ipString) : string
Parameters
- $ipString : string
-
The IP string (may contain multiple IPs)
Return values
string —The first IP address