Session that can be use only once

CodeIgniter supports “flashdata”, or session data that will only be available for the next request, and is then automatically cleared.

This can be very useful, especially for one-time informational, error or status messages (for example: “Record 2 deleted”).

It should be noted that flashdata variables are regular session vars, only marked in a specific way under the ‘__ci_vars’ key (please don’t touch that one, you’ve been warned).

To mark an existing item as “flashdata”:

$this->session->mark_as_flash('item');

If you want to mark multiple items as flashdata, simply pass the keys as an array:

$this->session->mark_as_flash(array('item', 'item2'));

To add flashdata:

$_SESSION['item'] = 'value';
$this->session->mark_as_flash('item');

Or alternatively, using the set_flashdata() method:

$this->session->set_flashdata('item', 'value');

You can also pass an array toset_flashdata(), in the same manner as set_userdata().

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!