Amey Joshi
Amey Joshi

Reputation: 1

Unset session array in codeigniter

I am trying to unset($_SESSION['cart']); it is not work 1st time once item is added in cart and I am trying to remove cart. But it is work fine when I refresh the same page again.but session is already created and it is printed on screen.

Upvotes: 0

Views: 3562

Answers (3)

user4419336
user4419336

Reputation:

I find unsettling session in array works better like

unset($_SESSION['cart']['some_item']);

Upvotes: 0

Aman
Aman

Reputation: 19

In codeigniter you have to unset the values of session by assigning null value to the session data like this(if you have multiple fields)

$unset_session = array('fields_that_session_contains'=>'');

$this->session->unset_userdata($unset_session);

you can also try this it will work

$this->session->sess_destroy();

i hope this will work for you

Upvotes: 1

Callombert
Callombert

Reputation: 1099

The codeigniter way, you should have this in your controller BEFORE the view is loaded:

$this->session->unset_userdata('cart');

Upvotes: 0

Related Questions