Why Is Laravel 5.5 Session Data Lost After Loggin Out?
I understand that laravel will generate a new session id when a user logs in, but in that case it retains the session data, but why does the data go away when the user logs out? So here is a method I am calling to get the CartID from the session:
public function getId()
{
if (!Auth::check()) {
if (!session()->has('CartID'))
session()->put('CartID', session()->getId());
return session('CartID');
}
else {
return session('CartID', '');
}
}
I pass the CartID from the above method and also the current session ID to a blade and display them. (this is just for devlopment purposes to "test" how this works.) So when I first go to website and I am NOT logged in it displays the same value for Cart ID and Session ID as one would expect. Then I login and go back to that page and then it displays the original (same) Cart ID but a new Session ID, which is also what one would expect. I have even tested completely closing my browser and reopening and when I go back I still have the original Cart ID with a different session ID (same as when it was closed). So this proves the session data is still intact after closing the browser. So far so good. However if I logout then go to the page the CartID has now changed to the new session ID, so I lost the original value of the Cart ID. This shows that when I logout I am losing all of my session data. Below is what I think might be useful from my session config file:
'driver' => env('SESSION_DRIVER', 'file'),
'lifetime' => 2880,
'expire_on_close' => false,
'encrypt' => true,
'domain' => env('SESSION_DOMAIN', null),
Can anyone explain why the session data is lost after logging out? I am running php 7.1 and Laravel 5.5 Thanks in advance
Answer
Because the session is invalidated: https://github.com/laravel/framework/blob/9a912d6f7da4d15144d73afc9213a5ef0f8db3e2/src/Illuminate/Foundation/Auth/AuthenticatesUsers.php#L157
Related Questions
- → "failed to open stream" error when executing "migrate:make"
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS create a multi select Form field
- → October CMS - Conditionally Load a Different Page
- → How to disable assets combining on development in OctoberCMS
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → OctoberCms component: How to display all ID(items) instead of sorting only one ID?
- → In OctoberCMS how do you find the hint path?
- → How to register middlewares in OctoberCMS plugin?