rlanvin/php-ip
PHP library for working with IPv4 and IPv6 addresses as objects, with subnet and range support. Parse, validate, and manipulate addresses, convert between formats, and calculate networks and masks through a clean, well-tested API.
X-Forwarded-For. If a feature needs containment, overlap, or enumeration, this library replaces bespoke bitwise math with a tested API and lets you scope that feature in days rather than weeks.IPv4, IPv6, IPv4Block, IPv6Block). That makes "do we support IPv6 in access rules / logging / customer config" a product choice rather than an engineering constraint — a materially cheaper decision to say yes to.Adopt when:
filter_var, ip2long, and inet_pton validate and convert but do not do this arithmetic.Look elsewhere or plan a spike when:
mlocati/ip-lib is the closest actively maintained comparator and covers ranges; a dedicated geo-IP database is a different purchase entirely.filter_var plus a regex is sufficient and you should not take the dependency.Recommendation: Run a short spike (a day, ideally against your actual allowlist/webhook/tenant-config paths) comparing this library with mlocati/ip-lib on PHP-version compatibility, extension requirements, and release cadence. Pick whichever passes your dependency policy; the API differences will not be the deciding factor.
For executives: We can add reliable network-based access control — allowlists, tenant subnet rules, trusted-proxy handling, webhook source verification — with a small, free, MIT-licensed library instead of custom code. The business case is risk reduction and speed: homegrown IP math is a known source of security defects (IPv6 bypasses, off-by-one subnet boundaries), and this package removes that class of bug from our surface area while making IPv6 support a config change rather than a project. Cost is near zero; integration is contained; the main governance question is that the last release was 2022, which for a stable, RFC-defined domain is low risk and is mitigated by a small codebase we could fork if needed. The high opportunity score reflects a real gap: PHP's built-in IP functions are validation-only, so teams either write this themselves or go without.
For engineering: Pure-PHP, in-process, no I/O, deterministic, and straightforward to unit test — a good fit for Laravel service classes and form requests. It gives you typed address and block objects with containment, overlap, splitting, and arithmetic, so policy code reads as intent rather than bit manipulation. Two things to confirm before we adopt: extension availability (GMP/BCMath) in our runtime images, and tested PHP-version coverage given the 2022 last release. If either is a problem, mlocati/ip-lib is the drop-in alternative with broader range support; I'd like a one-day spike comparing both against our actual webhook-validation and tenant-subnet paths, then a decision.
How can I help you explore Laravel packages today?