prezto / ipfilter
PSR-7 ip filter middleware. Sets the status code to 401 if needed according to user defined rules.
This package's canonical repository appears to be gone and the package has been frozen as a result.
Requires
- php: >=5.5.0
- psr/http-message: >=1.0
This package is not auto-updated.
Last update: 2024-10-24 00:56:00 UTC
README
PSR-7 IpFilter
##ALLOW mode
The default allow rule set allows all connections through except when the address matches
DENY mode
A default deny rule set will deny all connections through unless an address matches.
Usage
use Prezto\IpFilter\IpFilterMiddleware; use Prezto\IpFilter\Mode; # Instantiate with a single address. Allow only one ip. $filter = new IpFilterMiddleware(['192.168.1.7'], Mode::DENY) # Instantiate with an address range. Allow only this range. $filter = new IpFilterMiddleware([['192.168.1.100', '192.168.1.200']], Mode::DENY) # Adding addresses after instantiating. $filter->addIpRange('192.168.1.100', '192.168.1.200'); $filter->addIp('192.168.1.98');
After this you can add the class to a psr7 middleware loader that accepts $request, $response and next as parameters.
By default there is an error handler assigned when the user ois denied access. You can define your own by calling setHandler method and pass it a function/callable as parameter. The parameters of this function need to be $request, $response. If access is denied it will interupt the execution after calling the handler.