Laravel logout fail on pressing back button

前端 未结 5 1992
孤独总比滥情好
孤独总比滥情好 2021-01-06 18:17

On logout from my Laravel application using the Laravel logout method:

public function getLogout() 
    {
       Auth::logout();
       return Redirect::to(\         


        
5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-06 18:44

    Yes. As @Amelia wrote, that problem is because of browser cache but not Laravel. Sending response with no-cache is one solution, but that is not always good. You might have to pay a extra hosting fee if you implement that solution.

    I tried to solve this issue with a bit of javascript code in my base template just before tag.

    
    

    In the above code, replace http://local.myapp.in/login/ with your login page URL. So each time a page is loaded, this code gets executed. If the user is trying to access any restricted page without loggedin, then he will be redirected to login page. And if a user is trying to access login page when logged in, browser will be redirected to home page.

    Since, it is js code, even if the page is loaded from browser cache this piece of code runs.

提交回复
热议问题