blob: c41193c3c455314e8b0971219e00a54c43fb7ae9 [file] [log] [blame]
Derek Jones8ede1a22011-10-05 13:34:52 -05001#############
2Cookie Helper
3#############
4
5The Cookie Helper file contains functions that assist in working with
6cookies.
7
8.. contents:: Page Contents
9
10Loading this Helper
11===================
12
Andrey Andreev48a86752012-11-08 15:16:34 +020013This helper is loaded using the following code::
Derek Jones8ede1a22011-10-05 13:34:52 -050014
15 $this->load->helper('cookie');
16
17The following functions are available:
18
19set_cookie()
20============
21
Andrey Andreev48a86752012-11-08 15:16:34 +020022.. php:function:: set_cookie($name = '', $value = '', $expire = '', $domain = '', $path = '/', $prefix = '', $secure = FALSE, $httponly = FALSE)
23
24 :param string $name: Cookie name
25 :param string $value: Cookie value
26 :param int $expire: Number of seconds until expiration
27 :param string $domain: Cookie domain (usually: .yourdomain.com)
28 :param string $path: Cookie path
29 :param string $prefix: Cookie name prefix
30 :param bool $secure: Whether to only send the cookie through HTTPS
31 :param bool $httponly: Whether to hide the cookie from JavaScript
32 :returns: void
33
Derek Jones8ede1a22011-10-05 13:34:52 -050034This helper function gives you view file friendly syntax to set browser
Andrey Andreev48a86752012-11-08 15:16:34 +020035cookies. Refer to the :doc:`Input Library <../libraries/input>` for a
36description of its use, as this function is an alias for
37``CI_Input::set_cookie()``.
Derek Jones8ede1a22011-10-05 13:34:52 -050038
39get_cookie()
40============
41
Andrey Andreev48a86752012-11-08 15:16:34 +020042.. php:function:: get_cookie($index = '', $xss_clean = FALSE)
43
44 :param string $index: Cookie name
45 :param bool $xss_clean: Whether to apply XSS filtering to the returned value
46 :returns: mixed
47
Derek Jones8ede1a22011-10-05 13:34:52 -050048This helper function gives you view file friendly syntax to get browser
Andrey Andreev48a86752012-11-08 15:16:34 +020049cookies. Refer to the :doc:`Input Library <../libraries/input>` for a
50description of itsuse, as this function is an alias for ``CI_Input::cookie()``.
Derek Jones8ede1a22011-10-05 13:34:52 -050051
52delete_cookie()
53===============
54
Andrey Andreev48a86752012-11-08 15:16:34 +020055.. php:function:: delete_cookie($name = '', $domain = '', $path = '/', $prefix = '')
Derek Jones8ede1a22011-10-05 13:34:52 -050056
Andrey Andreev48a86752012-11-08 15:16:34 +020057 :param string $name: Cookie name
58 :param string $domain: Cookie domain (usually: .yourdomain.com)
59 :param string $path: Cookie path
60 :param string $prefix: Cookie name prefix
Derek Jones8ede1a22011-10-05 13:34:52 -050061 :returns: void
62
Andrey Andreev48a86752012-11-08 15:16:34 +020063Lets you delete a cookie. Unless you've set a custom path or other
64values, only the name of the cookie is needed.
65
Derek Jones8ede1a22011-10-05 13:34:52 -050066::
67
Andrey Andreev48a86752012-11-08 15:16:34 +020068 delete_cookie('name');
Derek Jones8ede1a22011-10-05 13:34:52 -050069
70This function is otherwise identical to ``set_cookie()``, except that it
71does not have the value and expiration parameters. You can submit an
72array of values in the first parameter or you can set discrete
73parameters.
74
75::
76
77 delete_cookie($name, $domain, $path, $prefix)