1. Go to this page and download the library: Download jasny/forwarded-middleware 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/ */
jasny / forwarded-middleware example snippets
use Wikimedia\IPSet;
use Jasny\Forwarded;
use Zend\Stratigility\MiddlewarePipe;
use Zend\Diactoros\ResponseFactory;
$trustIps = new IPSet(['208.80.154.0/26', '2620:0:861:1::/64', '10.64.0.0/22']);
$middleware = new Forwarded\Middleware(function (string $ip, array $forward) use ($trustedIps) {
return $trustedIps->match($ip);
});
$app = new MiddlewarePipe();
$app->pipe($middleware);
use Wikimedia\IPSet;
use Jasny\Forwarded;
use Zend\Stratigility\MiddlewarePipe;
use Zend\Diactoros\ResponseFactory;
$trustIps = new IPSet(['208.80.154.0/26', '2620:0:861:1::/64', '10.64.0.0/22']);
$compatMiddleware = new Forwarded\CompatMiddleware();
$middleware = new Forwarded\Middleware(function (string $ip, array $forward) use ($trustedIps) {
return $trustedIps->match($ip);
});
$app = new MiddlewarePipe();
$app->pipe($compatMiddleware);
$app->pipe($middleware);