How to Set & Get Tempdata in Codeigniter?

How to Set & Get Tempdata in Codeigniter

Set data as tempdata, we have to use mark_as_temp() function. This function takes two argument items first argument is a tempdata second one is a expiration time.

File Name :

// 'value' will be erased after 300 seconds(5 minutes)
$this->session->mark_as_temp('value',300);

You can also pass an array to store multiple data. All the items value stored below will be expired after 300 seconds.

$this->session->mark_as_temp(array('value1','value2'),300);

You can also set different expiration time for each item

// 'value1' will be erased after 250 seconds, while 'value2'
// will do so after only 300 seconds

$this->session->mark_as_temp(array(
'value1'=>250,
'value2'=>300
));

Retrieve Tempdata

We can retrieve the tempdata using tempdata() function.

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

Remove Tempdata

Tempdata is removed automatically after its expiration time but if you want to remove tempdata before that, then you can do as shown below using the unset_tempdata() function, which takes one argument of the item to be removed.

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





Previous Next


Trending Tutorials




Review & Rating

0.0 / 5

0 Review

5
(0)

4
(0)

3
(0)

2
(0)

1
(0)

Write Review Here