Skip to content

How to Set, Get and Delete Cookies in CodeIgniter ?

Last updated on January 17, 2018

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

Before using Cookie Helper functions you Should load cookie Helper, in the following 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);

0 0 votes
Article Rating
Subscribe
Notify of
guest

9 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments