Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How I Prevent Browser's Back Button Login After Logout

My problem is i can logout properly after i click to logout link but if i click to back button of the browser, still able to see the content of the page which actually should not be seen with respect to my auth middleware process. I read i can prevent this by disabling caching but don't think it is the best way to do this so how can i make this in a better way ?MY Logout Function is

public function logout()
{
    Auth::logout();
    Session::flush();
    return redirect('login');
}

My Route Is:

Route::get('logout','Homecontroller@logout');

Thanx In advance

like image 979
Diksha Avatar asked Jul 10 '15 06:07

Diksha


1 Answers

This problem is with the browser. The browser caches the content of the page and serves that cached content to the user when you are hitting the back button.

Set up cache-control meta tags on the pages that requires that a user is logged in. That way you are telling the browser not to cache it.

E.g:

<meta http-equiv="cache-control" content="private, max-age=0, no-cache">
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="expires" content="0">
like image 84
user2479930 Avatar answered Oct 12 '22 21:10

user2479930