如何访问 Laravel 上的 1 个 IP 的域或子域?
How make access to domain or subdomain for 1 IP on Laravel?
您好,如何访问 Laravel 上的 1 个静态 IP 的域?
我知道需要使用数组和$request->ip();
您可以使用名为 middleware 的东西。它充当您的请求和控制器之间的墙。示例中间件:
<?php
namespace App\Http\Middleware;
use Closure;
class FilterIps
{
const ALLOWED = [
'100.100.100.100',
];
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
abort_unless(in_array($request->ip(), self::ALLOWED), 403);
return $next($request);
}
}
激活它的示例方法是将它放在 app/Http/Kernel.php
文件中 $middlewareGroups
变量的 web
数组中:
use App\Http\Middleware\FilterIps;
/**
* The application's route middleware groups.
*
* @var array
*/
protected $middlewareGroups = [
'web' => [
// ...
FilterIps::class,
],
// ...
];
您好,如何访问 Laravel 上的 1 个静态 IP 的域?
我知道需要使用数组和$request->ip();
您可以使用名为 middleware 的东西。它充当您的请求和控制器之间的墙。示例中间件:
<?php
namespace App\Http\Middleware;
use Closure;
class FilterIps
{
const ALLOWED = [
'100.100.100.100',
];
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
abort_unless(in_array($request->ip(), self::ALLOWED), 403);
return $next($request);
}
}
激活它的示例方法是将它放在 app/Http/Kernel.php
文件中 $middlewareGroups
变量的 web
数组中:
use App\Http\Middleware\FilterIps;
/**
* The application's route middleware groups.
*
* @var array
*/
protected $middlewareGroups = [
'web' => [
// ...
FilterIps::class,
],
// ...
];