josantonius/ip
A lightweight PHP library for retrieving the client IP address, with helpers to validate IPs, detect private or reserved ranges, and handle proxied requests. Framework-agnostic and easy to drop into Laravel or any PHP project.
composer require josantonius/ip. There are no framework bindings, service providers, or config files — it is a single utility class.src/IP.php first. It's a tiny, static-only class; 5 minutes of reading tells you everything the README does not. Confirm which $_SERVER keys it inspects and what order it prefers before trusting it.$_SERVER['REMOTE_ADDR'] lookups in a controller, middleware, or logger with IP::get():use Josantonius\IP\IP;
$ip = IP::get();
IP::get() in ten places means ten places to fix when your proxy topology changes.null becomes '-' instead of an empty string.REMOTE_ADDR is the proxy, not the client. Configure the class to prefer the header your edge actually sets (X-Forwarded-For, CF-Connecting-IP, True-Client-IP, X-Real-IP). Only trust these when the immediate peer is a known proxy.filter_var($ip, FILTER_VALIDATE_IP) before persisting, geolocating, or rate-limiting on it.X-Forwarded-For and evade the limit trivially.IpResolver with a resolve(): ?string method) so tests can substitute a fake. This also isolates you from the package being archived.app/Support/Ip.php and own it. You get the same behavior, no abandoned dependency, and no lock-file churn.X-Forwarded-For is a list, not a value. It arrives as client, proxy1, proxy2. If you point the class at this header, you get the whole string back. Parse it yourself and take the left-most entry only after verifying the number of trusted hops.X-Forwarded-For: 1.2.3.4. If your app is directly internet-facing, trusting that header is a vulnerability. Only read forwarded headers when REMOTE_ADDR is in your known-proxy CIDR list.null (or an empty string, depending on the version — verify in source). Always coerce before writing to a VARCHAR IP column or a typed property.reset(). In PHPUnit this can quietly affect other tests in the same process — reset manually in tearDown.filter_var guard built in. The package does not validate; treat its output as untrusted input until you've validated it.$_SERVER['REMOTE_ADDR'] first, then the forwarded header. Nine times out of ten the class is behaving correctly and your proxy chain is the thing you're misreading.How can I help you explore Laravel packages today?