Laravel 根据$request->;ip()我得到了";::1“;在localhost上,我的控制器不能与白名单IP一起工作。请给我自定义错误
我有一个控制器,它应该允许使用一个IP的资源。如果IP无效,控制器应给出自定义错误“不正确的IP”。 但在执行控制器时,我不断得到自定义错误“Not correct IP”。 当我发送$request->ip()时,我得到“::1” 我正在使用localhost 我的控制器Laravel 根据$request->;ip()我得到了";::1“;在localhost上,我的控制器不能与白名单IP一起工作。请给我自定义错误,laravel,controller,request,ip,whitelist,Laravel,Controller,Request,Ip,Whitelist,我有一个控制器,它应该允许使用一个IP的资源。如果IP无效,控制器应给出自定义错误“不正确的IP”。 但在执行控制器时,我不断得到自定义错误“Not correct IP”。 当我发送$request->ip()时,我得到“::1” 我正在使用localhost 我的控制器 class OhDayHiepController extends Controller { const ALLOWED = [ "5.5.5.5", ]; publi
class OhDayHiepController extends Controller
{
const ALLOWED = [
"5.5.5.5",
];
public function whiteIP (Request $request)
{
abort_unless(in_array($request->ip(), self::ALLOWED), die("Not correct IP"));
return $request;
}
}
为什么我犯了错误,为什么我得到。可能是因为localhost需要定制::1“代表IPv6中的“localhost”。您似乎正在使用IPv4(xxx.xxx.xxx.xxx)
我不知道您想要实现什么目标,因此我无法确定您的解决方案,但您可以尝试使用::1“
,而不是中的“5.5.5.5”
还必须有一种方法将本地服务器配置为仅使用IPv4