CodeIgniter "flashdata" doesn't work

From the Codeigniter Session Class documentation, regarding Flashdata we can read:

CodeIgniter supports "flashdata", or session data that will only be available for the next server request, and are then automatically cleared.

Your problem might be that when you redirect, the process takes more than one request, clearing your flashdata.

To see if that's the case, just add the following code to the constructor of the controller you are redirecting to:

$this->session->keep_flashdata('message');

This will keep the flashdata for another server request, allowing it to be used afterwards.


I had that problem too. I don't remember where I saw but here's my solution.

redirect('url/myurl','refresh');

CodeIgniter didn't treated redirect as another request. So flashdata wasn't set in the redirect, but it was on the next page I loaded.


// Set flash data in our controller file

$this->session->set_flashdata('sessionkey', 'Value');

// After that we need to used redirect function

redirect("admin/signup");

// Get Flash data on view

$this->session->flashdata('sessionkey');