PHP code example of laravel-foundry / trusted-proxies
1. Go to this page and download the library: Download laravel-foundry/trusted-proxies 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/ */
laravel-foundry / trusted-proxies example snippets
// Get real client IP (not proxy IP)
$clientIp = request()->ip();
use Illuminate\Support\Facades\RateLimiter;
RateLimiter::for('api', function (Request $request) {
return Limit::perMinute(60)->by($request->ip());
});
namespace App\Http\Middleware;
class IpWhitelist
{
public function handle($request, $next)
{
$allowedIps = ['1.2.3.4', '5.6.7.8'];
if (!in_array(request()->ip(), $allowedIps)) {
abort(403, 'Access denied');
}
return $next($request);
}
}
// In tinker or any PHP file
$service = app(\LaravelFoundry\TrustedProxies\Service\TrustedProxyService::class);
var_dump(config('trustedproxies.providers'));
var_dump($service->getTrustedProxies());
var_dump(request()->ip());