What is Flash Data in CodeIgniter?

Flash data in CodeIgniter is a feature that allows you to store data for the next server request. It is a way to store data in a session for a single server request, after which the data is automatically deleted. This is useful for displaying messages or other information to the user after a form submission or other action.

In CodeIgniter, you can set flash data using the set_flashdata() function, like this:

$this->session->set_flashdata('message', 'Data has been saved successfully.');

You can then display the flash data in your view using the flashdata() function, like this:

echo $this->session->flashdata('message');

It's important to note that flash data can be accessed once, and it will be deleted after the next server request. If you need to keep the data for multiple requests, you should use session data instead.

You can also use the keep_flashdata() function to keep specific flash data for an additional request, like this:


You can also set a prefix for flash data if you need to keep multiple types of flash data for example for success and error messages

$this->session->set_flashdata('success_message', 'Data has been saved successfully.');
$this->session->set_flashdata('error_message', 'An error occurred while saving the data.');

Flash data is a powerful feature in CodeIgniter that allows you to easily store and display temporary data to the user, making it a useful tool for displaying notifications and messages on your application.


Added  Jan 26, 01:41 am

Article tags

SignUp with Email