codeigniter Cookie Helper Example

codeigniter Cookie Helper Example

codeigniter Cookie is a little bit of information sent from web server to store on user PC ro system. CodeIgniter has one partner called “codeigniter Cookie Helper” for codeigniter Cookie administration. The codeigniter Cookie Helper record contains capacities that help with working with treats.

What is a codeigniter Cookie ? A Cookie is frequently used to distinguish a client. A codeigniter Cookie is a little document that the server installs on the client’s PC. Each time a similar PC asks for a page with a program, it will send the codeigniter Cookie as well. With PHP, you can both make and recover codeigniter Cookie values.

This assistant is stacked utilizing the accompanying code:

// set codeigniter cookie helper

The accompanying capacities are accessible:

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

set_cookie Parameters:

  • $expire (int) – Number of seconds until expiration
  • $path (string) – Cookie path
  • $value (string) – Cookie value
  • $prefix (string) – Cookie name prefix
  • $domain (string) – Cookie space (as a rule:
  • $name (mixed) – Cookie name or cooperative exhibit of the majority of the parameters accessible to this function
  • $secure (bool) – Whether to just send the Cookie through HTTPS
  • $httponly (bool) – Whether to conceal the Cookie from JavaScript
  • Return sort :: void

This partner work gives you friendlier grammar to set program treats. Allude to the Input Library for a portrayal of its utilization, as this capacity is a nom de plume for CI_Input::set_cookie().

// get cookie
get_cookie($index[, $xss_clean = NULL])

get_cookie Parameters:

  • $xss_clean (bool) – Whether to apply XSS separating to the returned value
  • Returns: The Cookie esteem or NULL if not found
  • $index (string) – Cookie name
  • Return sort: mixed

This aide work gives you friendlier language structure to get program treats. Allude to the Input Library for nitty gritty portrayal of its utilization, as this capacity demonstrations likewise to CI_Input::cookie(), with the exception of it will likewise prepend the $config['cookie_prefix'] that you might’ve set in your application/config/config.php record.

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

delete_cookie Parameters:

  • $domain (string) – Cookie space (ordinarily:
  • $name (string) – Cookie name
  • $prefix (string) – Cookie name prefix
  • $path (string) – Cookie path
  • Return sort :: void

Gives you a chance to erase a Cookie. Unless you’ve set a custom way or different qualities, just the name of the Cookie is required.

// delete cookie

This capacity is generally indistinguishable to set_cookie(), aside from that it doesn’t have the esteem and termination parameters. You can present a variety of qualities in the principal parameter or you can set discrete parameters.

Example set, get, delete codeigniter cookie

Hear we will give you example of set, get, delete codeigniter cookie and how to implement it in codeigniter controller. Create a controller called Example_Cookie_controller.php and save it at application/controller/Example_Cookie_controller.php

class Example_Cookie_controller extends CI_Controller {

function __construct() {
// set cookie helper
$this->load->helper(array('cookie', 'url'));

public function index() {
// display page

public function display_cookie() {
echo get_cookie('your_cookie_name');
// display page

public function delete_cookie() {


Create a view file for Cookie view called Cookie_view.php and save it at application/views/Cookie_view.php

<!DOCTYPE html>
<html lang = "en">

<meta charset = "utf-8">
<title>Example Cookie Example - onlinecode</title>

<a href = 'cookie-display'>Click Here</a> to <b>Display</b> Your cookie.<br>
<a href = 'cookie-delete'>Click Here</a> to <b>Delete</b> Your cookie.


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'] = "Example_Cookie_controller";
// route display cookie
$route['cookie/cookie-display'] = "Example_Cookie_controller/display_cookie";
// route delete cookie
$route['cookie/cookie-delete'] = "Example_Cookie_controller/delete_cookie";

After that, you can execute the following URL in the browser to execute the example.

You also like Angular Gauge chart and Angularjs Image Gallery and Angularjs pie chart and Vuejs WYSIWYG Editor and angular 2 gauge chart

Leave a Comment

Your email address will not be published. Required fields are marked *

69  +    =  79

We're accepting well-written guest posts and this is a great opportunity to collaborate : Contact US