alsar / stack-ip-restrict
Stack middleware for allowing application access for specific IP addresses
Installs: 4 865
Dependents: 0
Suggesters: 0
Security: 0
Stars: 31
Watchers: 3
Forks: 6
Open Issues: 1
Requires
- php: >=5.4
- symfony/http-foundation: ^2.1||^3||^4
- symfony/http-kernel: ^2.1||^3||^4
Requires (Dev)
- phpunit/phpunit: ^3.7
- silex/silex: ^1.0
- stack/builder: ^1.0
This package is auto-updated.
Last update: 2024-12-15 18:08:21 UTC
README
Stack middleware to restrict application access for specific IP addresses.
Usage
Silex example
require __DIR__ . '/../vendor/autoload.php'; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Alsar\Stack\IpRestrict; $app = new Silex\Application(); $app->get('/', function(Request $request) { return new Response('Hello world!', 200); }); $app = (new Stack\Builder()) ->push('Alsar\Stack\IpRestrict', ['127.0.0.1']) ->resolve($app) ; $request = Request::createFromGlobals(); $response = $app->handle($request)->send(); $app->terminate($request, $response);
Symfony example
# web/app_dev.php use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Debug\Debug; $loader = require_once __DIR__.'/../app/bootstrap.php.cache'; Debug::enable(); require_once __DIR__.'/../app/AppKernel.php'; $kernel = new AppKernel('dev', true); $kernel->loadClassCache(); $stack = (new Stack\Builder()) ->push('Alsar\Stack\IpRestrict', ['127.0.0.1', 'fe80::1', '::1']); $kernel = $stack->resolve($kernel); Request::enableHttpMethodParameterOverride(); $request = Request::createFromGlobals(); $response = $kernel->handle($request); $response->send(); $kernel->terminate($request, $response);
Intallation
The recommended way to install this library is through Composer:
{ "require": { "alsar/stack-ip-restrict": "~1.0" } }
License
This library is released under the MIT License. See the bundled LICENSE file for details.