litphp / middleware-ip-address
v0.9.0
2019-06-29 12:37 UTC
Requires
- php: >=7.1.0
- litphp/nimo: ^0.9
- psr/http-message: ^1.0
Requires (Dev)
- phpstan/phpstan-phpunit: ^0.11.2
- phpstan/phpstan-shim: ^0.11.7
- phpunit/phpunit: ^7.5
- squizlabs/php_codesniffer: ^3.4
- zendframework/zend-diactoros: ^1.8
- zendframework/zend-httphandlerrunner: ^1.0
This package is auto-updated.
Last update: 2024-11-29 05:26:49 UTC
README
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