mlocati/ip-lib
A PHP library to parse, match, and manipulate IPv4 and IPv6 addresses, CIDR subnets, and address ranges, with support for wildcards, interval arithmetic, and network containment checks—useful for validation, access control, and IP math in any PHP project.
X-Forwarded-For against trusted proxy/load-balancer ranges so audit logs and rate limits aren't spoofable.Subnet::asPattern() end-address fix improves fidelity when we persist or export approved ranges.Adopt when:
ip2long overflows.Look elsewhere when:
Upgrade note (1.22.0 → 1.22.1): no new API, no deprecations, no breaking changes we rely on. Behavior tightens in two places: strings with trailing newlines or trailing text are now rejected rather than partially parsed, and IPv4-mapped IPv6 ranges/patterns are normalized to IPv4 form. Any stored allowlist entries or config values that previously "worked" only because of lenient parsing should be re-validated — that is a cleanup we want, not a regression.
For executives: This is a small, free, MIT-licensed building block that lets us ship IP-based access control and webhook verification faster and more safely. It replaces custom, security-sensitive parsing code that historically breaks on IPv6 — a known source of outages and audit findings. Adoption cost is a Composer dependency; switching costs later are low. It reduces risk and unblocks a class of network-aware features without new infrastructure or vendor spend. The project is actively maintained: the latest patch (1.22.1) is entirely correctness fixes on IPv6 and input-parsing edge cases — precisely the bugs we would otherwise inherit and have to debug in production.
For engineering: A mature, dependency-free PHP library for IPv4, IPv6, and IP ranges: parsing and validation, normalization, containment checks, and set operations (intersect, subtract, merge), with correct handling of v4-mapped-v6 addresses. Drop-in via Composer, no services or configuration, straightforward to unit test. It directly replaces ad-hoc ip2long/regex logic and is the correct primitive for trusted-proxy validation, allowlisting, and webhook source checks.
Upgrade to 1.22.1 is recommended and low-risk: no API changes. It fixes Subnet::asPattern() returning the wrong end address, fixes Pattern::toString() for IPv6 patterns with an IPv4-mapped prefix, uses the IPv4 range type for IPv4-mapped IPv6 ranges, and — relevant to our threat model — no longer accepts trailing newlines or trailing text when parsing addresses, nor malformed IPv6 reverse-DNS names. If we log or compare raw parsed values, expect cleaner canonical output; add a regression test asserting rejection of trailing whitespace/newline input in any allowlist code path.
It is deliberately scoped: bring your own geolocation or threat data if the roadmap needs it.
How can I help you explore Laravel packages today?