Supun Madhushanka
Supun Madhushanka

Reputation: 139

Session message repeat when click browser back

I want to show a session message after login. i do it using this

@if ($message = Session::get('success'))
   <script>
       toastr.success('{{ $message }}');
   </script>
@endif

but when navigate another web page and click again browser back button . it shows previous session message . How can i remove session messages on browser back button.

I tried

{{ Session::forget('success') }}

it always forget session message. Even not display first time session.

Upvotes: 0

Views: 567

Answers (1)

Dhairya Lakhera
Dhairya Lakhera

Reputation: 4808

Its because of cache.

you can use headers before sending response

header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");

There is a answer that can help you prevent-browsers-back-button-login-after-logout-in-laravel

Upvotes: 1

Related Questions