Skip to content

PSR-15 middleware for get client ip address

License

Notifications You must be signed in to change notification settings

litphp/middleware-ip-address

Repository files navigation

LitPHP/middleware-ip-adress

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

About

PSR-15 middleware for get client ip address

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages