পৃষ্ঠাসমূহ

Search Your Article

CS

 

Welcome to GoogleDG – your one-stop destination for free learning resources, guides, and digital tools.

At GoogleDG, we believe that knowledge should be accessible to everyone. Our mission is to provide readers with valuable ebooks, tutorials, and tech-related content that makes learning easier, faster, and more enjoyable.

What We Offer:

  • 📘 Free & Helpful Ebooks – covering education, technology, self-development, and more.

  • 💻 Step-by-Step Tutorials – practical guides on digital tools, apps, and software.

  • 🌐 Tech Updates & Tips – simplified information to keep you informed in the fast-changing digital world.

  • 🎯 Learning Support – resources designed to support students, professionals, and lifelong learners.

    Latest world News 

     

Our Vision

To create a digital knowledge hub where anyone, from beginners to advanced learners, can find trustworthy resources and grow their skills.

Why Choose Us?

✔ Simple explanations of complex topics
✔ 100% free access to resources
✔ Regularly updated content
✔ A community that values knowledge sharing

We are continuously working to expand our content library and provide readers with the most useful and relevant digital learning materials.

📩 If you’d like to connect, share feedback, or suggest topics, feel free to reach us through the Contact page.

Pageviews

Tuesday, February 14, 2017

CodeIgniter - Cookie Management

Cookie is a small piece of data sent from web server to store on client’s computer. CodeIgniter has one helper called “Cookie Helper” for cookie management.
Syntax set_cookie($name[, $value = ''[, $expire = ''[, $domain = ''[, $path = '/'[, $prefix = ''[, $secure = FALSE[, $httponly = FALSE]]]]]]]])
Parameters
  • $name (mixed) − Cookie name or associative array of all of the parameters available to this function
  • $value (string) − Cookie value
  • $expire (int) − Number of seconds until expiration
  • $domain (string) − Cookie domain (usually: .yourdomain.com)
  • $path (string) − Cookie path
  • $prefix (string) − Cookie name prefix
  • $secure (bool) − Whether to only send the cookie through HTTPS
  • $httponly (bool) − Whether to hide the cookie from JavaScript
Return Type void
In the set_cookie() function, we can pass all the values using two ways. In the first way, only array can be passed and in the second way, individual parameters can also be passed.
Syntax get_cookie($index[, $xss_clean = NULL]])
Parameters
  • $index (string) − Cookie name
  • $xss_clean (bool) − Whether to apply XSS filtering to the returned value
Return The cookie value or NULL if not found
Return Type mixed
The get_cookie() function is used to get the cookie that has been set using the set_cookie() function.
Syntax delete_cookie($name[, $domain = ''[, $path = '/'[, $prefix = '']]]])
Parameters
  • $name (string) − Cookie name
  • $domain (string) − Cookie domain (usually: .yourdomain.com)
  • $path (string) − Cookie path
  • $prefix (string) − Cookie name prefix
Return Type void
The delete_cookie() function is used to delete the cookie().

Example

Create a controller called Cookie_controller.php and save it at application/controller/Cookie_controller.php
<?php 
   class Cookie_controller extends CI_Controller { 
 
      function __construct() { 
         parent::__construct(); 
         $this->load->helper(array('cookie', 'url')); 
      } 
  
      public function index() { 
         set_cookie('cookie_name','cookie_value','3600'); 
         $this->load->view('Cookie_view'); 
      } 
  
      public function display_cookie() { 
         echo get_cookie('cookie_name'); 
         $this->load->view('Cookie_view');
      } 
  
      public function deletecookie() { 
         delete_cookie('cookie_name'); 
         redirect('cookie/display'); 
      } 
  
   } 
?>
Create a view file called Cookie_view.php and save it at application/views/Cookie_view.php
<!DOCTYPE html> 
<html lang = "en">
 
   <head> 
      <meta charset = "utf-8"> 
      <title>CodeIgniter View Example</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>
Change the routes.php file in application/config/routes.php to add route for the above controller and add the following line at the end of the file.
$route['cookie'] = "Cookie_controller"; 
$route['cookie/display'] = "Cookie_controller/display_cookie"; 
$route['cookie/delete'] = "Cookie_controller/deletecookie";
After that, you can execute the following URL in the browser to execute the example.
http://yoursite.com/index.php/cookie
It will produce an output as shown in the following screenshot.
cookie_management

No comments:

Post a Comment