Skip to main content

How to Set, Get and Delete Cookies in CodeIgniter ?

We can Set,Get and Delete Cookies with CodeIgniter Cookie Helper, Cookie Helper contain functions that assist in working with cookies.

Be fore using Cookie Helper functions you Should load cookie Helper , in the fallowing way :


$this->load->helper('cookie');


The Fallowing functions are available with Cookie Helper :
set_cookie(), get_cookie() ,delete_cookie()

Note :
set_cookie() is alias to $this->input->set_cookie();
get_cookie() is alias to $this->input->cookie();

Sample Code :

// set cookie
$cookie = array(
'name' => 'home_set',
'value' => 'home page Change',
'expire' => time()+86500,
'domain' => '.localhost',
'path' => '/',
'prefix' => 'arjun_',
);

set_cookie($cookie);

// get cookie

get_cookie('arjun_home_set');

// delete cookie
$cookie = array(
'name' => 'home_set',
'value' => '',
'expire' => '0',
'domain' => '.localhost',
'prefix' => 'arjun_'
);

delete_cookie($cookie);


I hope you like this Post, Please feel free to comment below, your suggestion and problems if you face - we are here to solve your problems.