Prevent Browser's Back Button Login After Logout in Laravel 5

前端 未结 8 828
情歌与酒
情歌与酒 2020-12-01 02:50

I am new to Laravel 5 and trying to make a simple authentication page. My problem is i can logout properly after i click to logout link but if i click to back button of the

8条回答
  •  广开言路
    2020-12-01 03:50

    Yeah its just a browser behavior, not any issue from laravel side but this could be a security issue. Here is how i solved it,

    1. Create new middleware

    php artisan make: middleware PreventBackHistory

    1. Replace middleware function handle
        $response = $next($request);
        $response->headers->set('Cache-Control','nocache, no-store, max-age=0, must-revalidate');
        $response->headers->set('Pragma','no-cache');
        $response->headers->set('Expires','Sun, 02 Jan 1990 00:00:00 GMT');
        return $response;
    
    1. Include path in Kernal

    'prevent-back-history' => \App\Http\Middleware\PreventBackHistory::class

    1. Update Routes

    Route::group(['middleware' => ['prevent-back-history','otherMiddlewares']]

    It will work for you!

提交回复
热议问题