Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to clear session variables in symfony2

Tags:

php

symfony

I am setting session variable with this

$session->get('user_id'); 

I want to clear all session data or single variable. How can i do that

like image 326
Mirage Avatar asked Aug 22 '12 06:08

Mirage


People also ask

Can you edit session variables?

Session variables on the client are read-only. They cannot be modified.

What is session in Symfony?

Symfony provides a session object and several utilities that you can use to store information about the user between requests.


2 Answers

Visit this link

http://api.symfony.com/master/Symfony/Component/HttpFoundation/Session/Session.html#remove%28%29

$session->remove('user_id');

like image 133
gaurang171 Avatar answered Sep 27 '22 20:09

gaurang171


To clear all session data (attributes) you should use clear. Example:

$session->clear(); 

Please also see Symfony session attributes documentation.

like image 42
NHG Avatar answered Sep 27 '22 19:09

NHG