How to remove cache of a specific page

when implementing authentication in laravel using sentinel and logout, then if I press the "return to one page" button of any browser, it returns to the control panel. If the page is refreshed, it goes to the login page as necessary. But I want to prevent access to the control panel without updating.

  • How to remove the cache of this particular page immediately after logging out?
  • How do I know any specific browser cache on a page and Laravel's approach to doing this?

NB After exiting the system and moving to the dashboard, this will prevent anything from changing as needed.

+5
source share
1 answer

Destroy the session when you call the logout function. Just write your exit function to your controller as follows:

public function getLogout() { Sentry::logout(); Session::flush(); // Insert this line, it will remove all the session data return Redirect::to('users/login')->with('message', 'Your are now logged out!'); } 

Edit:

At first I used only Session: flush (), and somehow it worked! But when I checked again, I found that it was not working. So, we need to add another code to clear the browser cache upon logout.

Using a filter may be the solution to this problem. (I have not found another solution yet). First add this code to filters.php:

 Route::filter('no-cache',function($route, $request, $response){ $response->header("Cache-Control","no-cache,no-store, must-revalidate"); $response->header("Pragma", "no-cache"); //HTTP 1.0 $response->header("Expires"," Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past }); 

Then attach this filter to routes or controllers. I bound it to the controller build function as follows:

 public function __construct() { $this->beforeFilter('csrf',array('on' => 'post')); $this->afterFilter("no-cache", ["only"=>"getDashboard"]); } 
+1
source

Source: https://habr.com/ru/post/1206901/


All Articles