litphp/middleware-ip-address

v0.9.0 2019-06-29 12:37 UTC

This package is auto-updated.

Last update: 2024-10-29 05:10:41 UTC


README

Scrutinizer Code Quality Code Coverage Build Status

PSR-15 middleware for get client ip address from request

a complete rewrite of akrabat/rka-ip-address-middleware, using most of it's test cases

Features

  • based on PSR-15
  • require PHP>=7.1 (for nullable typehint, and 7.0's lifecycle is in fact shorter than 5.6)
  • MUST provide $trustedProxies in order to inspect forwarding headers (security by default)
  • instead of use magic attribute name, use class name to attach the class instance to request

Example

<?php
use Lit\Middleware\IpAddress;

//bootstraping
$ipAddress = new IpAddress(['YOUR_TRUSTED_REVERSE_PROXY']);
ADD_MIDDLEWARE_TO_YOUR_APP($ipAddress, $app);

//in your business logic
$ip = IpAddress::fromRequest($request)->getIpAddress(); //string|null