Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Laravel:如何防止使用同一用户帐户多次登录?_Php_Laravel - Fatal编程技术网

Php Laravel:如何防止使用同一用户帐户多次登录?

Php Laravel:如何防止使用同一用户帐户多次登录?,php,laravel,Php,Laravel,如何防止在任何类型的浏览器中使用相同的用户凭据多次登录?谢谢您…您可以使用auth()->登录其他设备($request->password)功能 参考链接 它将注销具有相同用户的所有其他用户 LoginController.php中的 添加此代码 use Illuminate\Support\Facades\Auth; /** * Send the response after the user was authenticated. * * @param

如何防止在任何类型的浏览器中使用相同的用户凭据多次登录?谢谢您…

您可以使用
auth()->登录其他设备($request->password)功能

参考链接

它将注销具有相同用户的所有其他用户

LoginController.php中的
添加此代码

 use Illuminate\Support\Facades\Auth;

 /**
     * Send the response after the user was authenticated.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    protected function sendLoginResponse(Request $request)
    {
        $request->session()->regenerate();

        $this->clearLoginAttempts($request);

        if ($response = $this->authenticated($request, $this->guard()->user())) {
            return $response;
        }
        auth()->logoutOtherDevices($request->password);
        return $request->wantsJson()
                    ? new Response('', 204)
                    : redirect()->intended($this->redirectPath());
    }
在上述代码中,覆盖laravel内部使用的相同代码

auth()->登录其他设备($request->password)是在您需要此功能时添加的

您需要在app/Http/Kernel.php类的web中间件组中取消注释:

'web'=>[
// ...
\Illumb\Session\Middleware\AuthenticateSession::class,
// ...
],

谢谢……非常感谢。。。maraming salamat po,,,在哪里可以添加此功能?非常感谢。它的魅力。。。