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()

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);	


Related FAQ

Here are some more FAQ related to this Article:

  1.   Class 'App\Providers\View' not found in Laravel
  2.   How to Check If Array is Empty in Laravel Blade?
  3.   Laravel User Role based Access control Authentication
  4.   Laravel updateOrCreate, firstOrNew, firstOr and firstOrCreate Methods
  5.   PHP Resize Image Upload Example
  6.   Laravel Dynamic Change page Title Tags
  7.   Laravel 5.8 Form Validation Using Jquery
  8.   CKEditor Upload files Custom File Manager using PHP
  9.   Laravel MySQL Get Last Inserted ID
  10.   Get Current Url Parameter using Laravel