Search by

Resolves the real client IP behind proxies and merges it into the Laravel request.

Package info

github.com/perfocard/ip

pkg:composer/perfocard/ip

Statistics

Installs: 13

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0.0 2026-09-09 09:31 UTC

This package is auto-updated.

Last update: 2026-09-09 09:37:17 UTC


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:

  1. CF-Connecting-IP
  2. True-Client-IP
  3. Fastly-Client-IP
  4. Fly-Client-IP
  5. X-Real-IP
  6. X-Client-IP
  7. X-Forwarded-For (leftmost public IP)
  8. Forwarded (RFC 7239 for=, leftmost public IP)
  9. REMOTE_ADDR