In this tutorial we will learn about CodeIgniter Cookie Management. Cookie is a small piece of data that can be stored on the client’s computer from the web server. CodeIgniter has a Cookie Helper for the management of cookies.

Syntax set_cookie($name[, $value = ”[, $expire = ”[, $domain = ”[, $path = ‘/’[, $prefix = ”[, $secure = FALSE[, $httponly = FALSE]]]]]]]])
Parameters
  • $name (mixed) − Name of the cookie or associative array of all parameters for this feature
  • $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 send the cookie only via HTTPS
  • $httponly (bool) − Whether to hide the JavaScript cookie
Return Type void

All values can be passed in two ways in the set_cookie() function. Only array can be passed on the first way and individual parameters can also be passed on the second way.

Syntax get_cookie($index[, $xss_clean = NULL]])
Parameters
  • $index (string) − Cookie name
  • $xss_clean (bool) − Whether XSS filtering is applied to the returned value
Return The value of the cookie or NULL if not found
Return Type mixed

The get_cookie() function is used to use the set_cookie() function to obtain the cookie.

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) − Prefix Cookie Name
Return Type void

The function delete_cookie() is used to remove cookie().