I am saving the current user s data in a session, I am using Symfony 4.4
I am getting and setting the data to the session variable this way
$session = $this->get('session');
$session->set('user', $user);
is there any way to clear and delete the session after logging out
I tried
$session->invalidate();
and deleting the session one by using remove and nothing happened
$session->remove('user');
My Answer:
get('session');
$session->set('user', $userData);
To delete or clear the session in Symfony 4.4, you can use the following code:
$session->remove('user');
This will remove the 'user' data from the session. If you want to clear the entire session, you can use:
$session->clear();
This will remove all data from the session.
Rate this post
4 of 5 based on 9657 votesComments