PHP code example of neophp / ip-whitelist-package

1. Go to this page and download the library: Download neophp/ip-whitelist-package 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/ */

    

neophp / ip-whitelist-package example snippets


// src/MyProject/Config/app.config.php
return [
    // ...
    'packages' => [
        \Vendor\NeoPHP\IpWhitelistPackage\IpWhitelistPackage::class,
    ],
];



declare(strict_types=1);

return [
    'allowed_ips' => [
        '127.0.0.1',
        '203.0.113.42',
    ],
];

use Neo\Core\Security\Middleware\Attribute\Middleware;
use Vendor\NeoPHP\IpWhitelistPackage\Middleware\IpWhitelistMiddleware;

#[Middleware(
    use: IpWhitelistMiddleware::class,
    message: 'Access restricted to whitelisted IPs.',
    onError: 'block',
)]
final class AdminController extends AbstractController
{
    // every action in this controller now 

final class ReportsController extends AbstractController
{
    #[Middleware(use: IpWhitelistMiddleware::class, onError: 'block')]
    #[Route(path: '/export', name: 'export', methods: ['GET'])]
    public function export(): Response
    {
        // ...
    }
}

ip-whitelist-package/
├── composer.json
├── README.md
├── src/
│   ├── IpWhitelistPackage.php
│   └── Middleware/
│       └── IpWhitelistMiddleware.php
└── config/
    └── ipwhitelist.config.php