1
votes

How can I go about unsetting flashdata using the Codeigniter Session library? I know flashdata normally expires after one page refresh, however I'm using AJAX in a portion of my app, and when setting flash data, it still exists if I make a second AJAX call, so I need a method of unsetting flashdata manually.

I thought this might work as it is similar to unsetting session userdata:

$this->session->unset_flashdata('some_val');

However it doesn't do anything, any suggestions?

1
how about unset_userdata($newdata = array()) (Delete a session variable from the "userdata" array) ?? - David
I just wound up wrapping the flashdata in a DOM element, then deleted it on AJAX success, deleting it from the userdata array is also a good idea, although not necessary in my case. - dcd0181

1 Answers

2
votes

if you want to destroy all session value then use this:

$this->session->sess_destroy();

and if you want to destroy a particulat session the use:

$this->session->unset_flashdata('session name');

or

$sessionvar = $this->session->userdata('sessionname');
unset($sessionvar);

if this is not working then use following to empty the session value:

$this->session->set_flashdata("sessionname","");