[英]How make access to domain or subdomain for 1 IP on Laravel?
Hello how make access to domain for 1 static IP on Laravel?您好,如何在 Laravel 上访问域 1 static IP?
I know need use array and $request->ip();
我知道需要使用数组和$request->ip();
You can use something called middleware .您可以使用称为中间件的东西。 It serves as a wall between your request and controllers.它充当您的请求和控制器之间的墙。 Example 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);
}
}
Example way to activate it is to put it in web
array in $middlewareGroups
variable inside your app/Http/Kernel.php
file:激活它的示例方法是将它放在app/Http/Kernel.php
文件中$middlewareGroups
变量的web
数组中:
use App\Http\Middleware\FilterIps;
/**
* The application's route middleware groups.
*
* @var array
*/
protected $middlewareGroups = [
'web' => [
// ...
FilterIps::class,
],
// ...
];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.