perfocard / ip
Resolves the real client IP behind proxies and merges it into the Laravel request.
Requires
- php: ^8.3
- illuminate/http: ^11.0|^12.0|^13.0
- illuminate/support: ^11.0|^12.0|^13.0
Requires (Dev)
None
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Resolves the real client IP behind Cloudflare, load balancers, and web servers, then merges it into the Laravel request so $request->ip() returns the client address.
The package registers ResolveIp as global middleware automatically. No installer command.
Installation
composer require perfocard/ip
Publish the config if you need to change header priority:
php artisan vendor:publish --tag=config --provider="Perfocard\Ip\IpServiceProvider"
Local override
Set a fixed IP in .env so local requests are not always 127.0.0.1:
IP_ADDRESS=203.0.113.10
Leave it empty to parse proxy headers.
Trusted proxies
$request->ip() does not need trustProxies in the host app. ResolveIp writes the resolved address into REMOTE_ADDR before Laravel's TrustProxies middleware runs.
HTTPS, host, and port behind Cloudflare or a load balancer are a separate concern. Configure that in the application, not in this package:
$middleware->trustProxies( at: '*', headers: Request::HEADER_X_FORWARDED_FOR | Request::HEADER_X_FORWARDED_HOST | Request::HEADER_X_FORWARDED_PORT | Request::HEADER_X_FORWARDED_PROTO | Request::HEADER_X_FORWARDED_AWS_ELB, );
at: '*' trusts every hop. Prefer known proxy CIDRs when the origin is reachable without the gateway.
Header order
The parser inspects headers in this order and takes the first valid IP:
CF-Connecting-IPTrue-Client-IPFastly-Client-IPFly-Client-IPX-Real-IPX-Client-IPX-Forwarded-For(leftmost public IP)Forwarded(RFC 7239for=, leftmost public IP)REMOTE_ADDR