gpt4 book ai didi

php - 在 Laravel 中使用 HTTP Basic Auth 注销

转载 作者:可可西里 更新时间:2023-11-01 12:29:47 24 4
gpt4 key购买 nike

我有一个用户类,它由两种类型的用户组成,我想允许不同的用户访问不同的页面。

我创建了一个过滤器如下

Route::filter('isExpert', function()
{
$userIsExpert = 0;
$userIsLoggedIn = Auth::check();
if ($userIsLoggedIn && Auth::user()->role == 'expert') {
$userIsExpert = 1;
}

Log::info('Logged in: ' . $userIsLoggedIn . ' && Expert: ' . $userIsExpert);
if ($userIsExpert == 0)
{
Log::info('should be logging out now.');
Auth::logout();
return Auth::basic();
}
});

像这样路由

Route::get('/winners', array('before' => 'isExpert', function()
{
$winners = DB::select('select * from winners');
return View::make('winners.index')->with('winners',$winners);
}));

思路是这样的:如果不是专家,它会注销并重定向到登录页面。如果是,它将继续。但是, Auth::logout();永远不会注销用户。

问题

为什么 Auth::logout() 不工作?我试过将它放在应用程序中的任何位置,但无济于事。

干杯

最佳答案

我遇到了同样的问题,我真的无法注销当前用户...答案很简单:Laravel 不支持使用 Auth::basic() 的 logout()。

修复方法有,但不是很干净; https://www.google.nl/search?q=logout+basic

关于php - 在 Laravel 中使用 HTTP Basic Auth 注销,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18295994/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com