CodeIgniter supports tempdata data with a specific expiration time. After the value expires the value is automatically removed.

Flashdata and Tempdata are Similar variables are marked in a specific way under the __ci_vars key.

mark_as_temp() method is use to mark an existing item as tempdata simply pass it key and expiry time

Add Tempdata

// 'item' will be erased after 300 seconds
$this->session->mark_as_temp('key', 300);

There are two ways You can mark tempdata depending on whether you want them all to have the same expiry time or not:

// Both 'key' and 'key2' will expire after 300 seconds
$this->session->mark_as_temp(array('key', 'key2'), 300);

// 'item' will be erased after 300 seconds, while 'key'
// will do so after only 240 seconds
$this->session->mark_as_temp(array(
        'key'  => 300,
        'key2' => 240
));

Retrieve Tempdata

We can retrieve the tempdata using tempdata() function. This function to you are getting only tempdata and not any other data. How to retrieve tempdata with the following code line. tempdata() function is use to take one argument of the item to be fetched.

$this->session->tempdata('key');

Remove Tempdata

However, this won’t remove the marker that makes this specific item to be tempdata it will be invalidated on the next HTTP request so if you intend to reuse that same key in the same request, you’d want to use unset_tempdata():

$this->session->unset_tempdata('key');