PHP code example of middlewares / firewall

1. Go to this page and download the library: Download middlewares/firewall 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/ */

    

middlewares / firewall example snippets


Dispatcher::run([
    (new Middlewares\Firewall(['123.0.0.*']))
        ->blacklist([
            '123.0.0.1',
            '123.0.0.2',
        ])
]);

$firewall = new Middlewares\Firewall([
    '127.0.0.1',
    '198.168.0.*',
]);

$responseFactory = new MyOwnResponseFactory();

$firewall = new Middlewares\Firewall($whitelist, $responseFactory);

$whitelist = [
    '127.0.0.1',
    '198.168.0.*',
];
$blacklist = [
    '192.168.0.50',
];

$firewall = (new Middlewares\Firewall($whitelist))->blacklist($blacklist);

Dispatcher::run([
    //detect the client ip and save it in client-ip attribute
    new Middlewares\ClientIP(),

    //use that attribute
    (new Middlewares\Firewall(['123.0.0.*']))
        ->ipAttribute('client-ip')
]);