Framework: [5.3] Old Session Isn't Flushed with Session::regenerate

Created on 6 Jan 2017  路  3Comments  路  Source: laravel/framework

  • Laravel Version: 5.3.28
  • PHP Version: 7.1
  • Database Driver & Version:

Description:

I am using file based Laravel session.

When running below code:

Session::forget('member');
Session::flush();
Session::regenerate();

The old session wasn't flush at all, all the data including the member info is still there. But the newly generated session start fresh.

How can I really flush the old session before moving to new session?

All 3 comments

I believe flush() clears the content of the session, but does not automatically persist the changes. They are persisted at the end of the current request, however, the call to regenerate() will start a new session, and that is the session that is persisted. Could you try to sneak in a call to Session::save(); after Session::flush();?

It also looks like the regenerate method accepts an optional boolean to destroy the session. So possibly, Session::regenerate(true); would help. If that is the case, then flush would probably be unnecessary.

@sisve Thanks for pointing out. Session::save() does the trick.

@devcircus Session::regenerate(true) does clear the old session file, but doesn't clear the previous session data if you didn't flush. Thus, below is my new code:

Session::flush();
Session::regenerate(true);

Thank you for your help. Have a nice day.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Fuzzyma picture Fuzzyma  路  3Comments

kerbylav picture kerbylav  路  3Comments

gabriellimo picture gabriellimo  路  3Comments

lzp819739483 picture lzp819739483  路  3Comments

Anahkiasen picture Anahkiasen  路  3Comments