PHP code example of abouvier / slim-access

1. Go to this page and download the library: Download abouvier/slim-access library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

abouvier / slim-access example snippets


use \Slim\Middleware\Access;
// ...
$app = new \Slim\Slim();
// ...
$app->add(new Access([
	'callback' => function () use ($app) {
		$app->halt(403, 'You Shall Not Pass!!!');
	},
	'list' => [
		'::1' => Access::ALLOW,
		'127.0.0.1' => Access::ALLOW,
		'192.168.1.42' => Access::DENY,
		'192.168.1.0/24' => Access::ALLOW,
		'all' => Access::DENY // optional as "all" is already denied by default
	]
]));
// ...
$app->run();

$app = new \Slim\Slim();
// ...
$access = new \Slim\Middleware\Access([
	'callback' => function () use ($app) {
		$app->halt(403, 'You Shall Not Pass!!!');
	}
]);
$access->allow('::1')->allow('127.0.0.1')->deny('192.168.1.42')->allow('192.168.1.0/24')->deny('all');
$app->add($access);
// ...
$app->run();