CodeIgniter Cookie is the small text file that is stored in the browser of visitor’s computer. Cookies help the server to quickly access the information of users who visit the same pages again and again. CodeIgniter uses Cookie Helper function to organize Cookies.
set_cookie() function sets the cookie in which all the values can be passed in two ways. In the first process, only the array will be passed and in the second process, each parameter is passed individually. The syntax for set_cookie() function is as follows.
[php]set_cookie($name[, $value = ''[, $expire = ''[, $domain = ''[, $path = '/'[, $prefix = ''[, $secure = FALSE[, $httponly = FALSE]]]]]]])[/php]
where,
$name
(mixed) => Name of Cookie or the respective array with parameters available to the function.
$value
(string) => Value of Cookie
$expire
(int) => Expiration duration of Cookie in seconds
$domain
(string) => Domain of Cookie (Mostly: .yourdomain.com)
$path
(string) => Path of Cookie
$prefix
(string) => Prefix name of Cookie
$secure
(bool) => Decision factor of to confirm in forwarding the cookie through HTTPS
$httponly
(bool) => Deciding factor in hiding the cookie from browser JavaScript
Using get_cookie() function, the value of specified cookie set in setcookie() function can be returned and the syntax will be as follows.
[php]
get_cookie($index[, $xss_clean = NULL]])
[/php]
where,
$index
(string) => name of cookie
$xss_clean
(bool) => checks condition to apply XSS filtering to the returned value or not
delete_cookie() function deletes the cookie.
[php]
delete_cookie($name[, $domain = ''[, $path = '/'[, $prefix = '']]]])
[/php]
where,
$name
(mixed) => Name of Cookie
$domain
(string) => Domain of Cookie (Mostly: .yourdomain.com)
$path
(string) => Path of Cookie
$prefix
(string) => Prefix name of Cookie