PHP code example of chrishardie / laravel-synced-ip-allowlist

1. Go to this page and download the library: Download chrishardie/laravel-synced-ip-allowlist 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/ */

    

chrishardie / laravel-synced-ip-allowlist example snippets


return [
    // The URL where the encrypted list of IP addresses allowed in CIDR notation is available
    'allowed_ips_url' => env('ALLOWED_IPS_URL', 'https://example.com/allowed-ips.txt'),
    // The encryption key for encrypting and decrypting the list of IP addresses
    'allowed_ips_key' => env('ALLOWED_IPS_KEY', env('APP_KEY')),
    // The cache key used to store the list of allowed IP addresses
    'allowed_ips_cache_key' => 'allowed-ips.cidrs',
    // An optional URL to redirect unauthorized users to instead of showing a 403 error
    'unauthorized_redirect_url' => env('ALLOWED_IPS_REDIRECT_URL'),
];

protected $routeMiddleware = [
    'allowed-ips' => \ChrisHardie\SyncedIpAllowlist\Http\Middleware\RestrictByAllowedIps::class,
];

Route::middleware(['allowed-ips'])->group(function () {
    // Protected routes
    Route::get(...);
    Route::post(...);
});
bash
php artisan vendor:publish --tag="laravel-synced-ip-allowlist-config"
bash
php artisan artisan ip-allowlist:encrypt
bash
php artisan ip-allowlist:sync
bash
$ php artisan schedule:list | grep ip-allowlist
  0    1,13  *  * *        php artisan ip-allowlist:sync ..... Next Due: 11 hours from now