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

Today, We want to share with you set cookie in codeigniter.In this post we will show you Cookies In Codeigniter, hear for how to check cookie is set or not in codeigniter? we will give you demo and example for implement.In this post, we will learn about How to set (Create), Access and Delete Cookies? with an example.

how to set cookie in codeigniter?

here you can set, get and delete cookie in codeigniter Examples.
set cookie

set_cookie($name[, $value = ''[, $expire = ''[, $domain = ''[, $path = '/'[, $prefix = ''[, $secure = FALSE[, $httponly = FALSE]]]]]]])

get cookie

get_cookie($index[, $xss_clean = NULL]])

delete cookie

delete_cookie($name[, $domain = ''[, $path = '/'[, $prefix = '']]]])

step 1: application/config/autoload.php

$autoload['helper'] = array('url','cookie');

step 2: application/controller/Product_cart_controller.php

<?php
   class Product_cart_controller extends CI_Controller {
 
      function __construct() {
         parent::__construct();
         $this->load->helper(array('cookie', 'url'));
      }
 
      public function index() {
         set_cookie('shop_details','cookie_value','3600');
         $this->load->view('view_cookie');
      }
 
      public function display_cookie() {
         echo get_cookie('shop_details');
         $this->load->view('view_cookie');
      }
 
      public function deletecookie() {
         delete_cookie('shop_details');
         redirect('cookie/display');
      }
 
   }
?>

step 3: application/views/view_cookie.php

<!DOCTYPE html>
<html lang = "en">
 
   <head>
      <meta charset = "utf-8">
      <title>CodeIgniter View Example - www.pakainfo.com</title>
   </head>
 
   <body>
      <a href = 'display'>Click Here</a> to view the cookie.<br>
      <a href = 'delete'>Click Here</a> to delete the cookie.
   </body>
 
</html>

step 4: application/config/routes.php

$route['cookie'] = "Product_cart_controller"; 
$route['cookie/display'] = "Product_cart_controller/display_cookie"; 
$route['cookie/delete'] = "Product_cart_controller/deletecookie";

http://localhost/Codeigniter/index.php/cookie

I hope you get an idea about CodeIgniter Cookie Helper.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Also Read This 👉   date between in sql