How to set (Create), Access and Delete Cookies in codeigniter ?

I can easy way to Set, Get and Delete Cookies with PHP CodeIgniter using Cookie Helper, Cookie Helper data contains functions that assist in working with very well cookies set get and unset.

How to Set, Get and Delete Cookies in CodeIgniter?

Before using Cookie Helper functions you Should load cookie Helper, in the bellow methods :

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

The bellow functions are available with Cookie Helper methods: set_cookie(), get_cookie() and delete_cookie()

Read Also:  php percentage - how to get percentage of value in php ?

Also Read: Session Management in CodeIgniter with PHP

IMP Note :

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

set cookie expire time in codeigniter

set cookie

$cookieInfoData = array(
		'name'   => 'home_set',
		'value'  => 'Welcome To Pakainfo Website',
		'expire' => time()+86500,
		'domain' => '.localhost',
		'path'   => '/',
		'prefix' => 'pakainfo_',
		);

set_cookie($cookieInfoData);

how to get array in cookie

get cookie

get_cookie('pakainfo_home_set');

unset cookie in codeigniter

delete cookie

$cookieInfoData = array(
    'name'   => 'home_set',
    'value'  => '',
    'expire' => '0',
    'domain' => '.localhost',
    'prefix' => 'pakainfo_'
    );
delete_cookie($cookieInfoData);