blob: 22fd0f77f3fed2b3f664e28e3c4cfea6ccade586 [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
Derek Jonesb55d9812013-07-20 08:49:25 -07008.. contents::
9 :local:
10
11.. raw:: html
12
13 <div class="custom-index container"></div>
Derek Jones8ede1a22011-10-05 13:34:52 -050014
15Loading this Helper
16===================
17
Andrey Andreev48a86752012-11-08 15:16:34 +020018This helper is loaded using the following code::
Derek Jones8ede1a22011-10-05 13:34:52 -050019
20 $this->load->helper('cookie');
21
Derek Jonesb55d9812013-07-20 08:49:25 -070022Available Functions
23===================
24
Derek Jones8ede1a22011-10-05 13:34:52 -050025The following functions are available:
26
Derek Jones8ede1a22011-10-05 13:34:52 -050027
Andrey Andreev04535c72014-01-06 10:57:05 +020028.. function:: set_cookie($name[, $value = ''[, $expire = ''[, $domain = ''[, $path = '/'[, $prefix = ''[, $secure = FALSE[, $httponly = FALSE]]]]]]]])
Andrey Andreev48a86752012-11-08 15:16:34 +020029
Andrey Andreev3de130c2014-02-07 23:31:49 +020030 :param mixed $name: Cookie name *or* associative array of all of the parameters available to this function
31 :param string $value: Cookie value
32 :param int $expire: Number of seconds until expiration
33 :param string $domain: Cookie domain (usually: .yourdomain.com)
34 :param string $path: Cookie path
35 :param string $prefix: Cookie name prefix
36 :param bool $secure: Whether to only send the cookie through HTTPS
37 :param bool $httponly: Whether to hide the cookie from JavaScript
38 :rtype: void
Andrey Andreev48a86752012-11-08 15:16:34 +020039
Derek Jonesb55d9812013-07-20 08:49:25 -070040 This helper function gives you view file friendly syntax to set browser
41 cookies. Refer to the :doc:`Input Library <../libraries/input>` for a
42 description of its use, as this function is an alias for
43 ``CI_Input::set_cookie()``.
Derek Jones8ede1a22011-10-05 13:34:52 -050044
Derek Jones8ede1a22011-10-05 13:34:52 -050045
Andrey Andreev88ebdf72014-01-08 17:28:02 +020046.. function:: get_cookie($index[, $xss_clean = NULL]])
Andrey Andreev48a86752012-11-08 15:16:34 +020047
Andrey Andreev3de130c2014-02-07 23:31:49 +020048 :param string $index: Cookie name
49 :param bool $xss_clean: Whether to apply XSS filtering to the returned value
50 :returns: The cookie value or NULL if not found
51 :rtype: mixed
Andrey Andreev48a86752012-11-08 15:16:34 +020052
Derek Jonesb55d9812013-07-20 08:49:25 -070053 This helper function gives you view file friendly syntax to get browser
54 cookies. Refer to the :doc:`Input Library <../libraries/input>` for a
55 description of its use, as this function is an alias for ``CI_Input::cookie()``.
Derek Jones8ede1a22011-10-05 13:34:52 -050056
Derek Jones8ede1a22011-10-05 13:34:52 -050057
Andrey Andreev04535c72014-01-06 10:57:05 +020058.. function:: delete_cookie($name[, $domain = ''[, $path = '/'[, $prefix = '']]]])
Derek Jones8ede1a22011-10-05 13:34:52 -050059
Andrey Andreev3de130c2014-02-07 23:31:49 +020060 :param string $name: Cookie name
61 :param string $domain: Cookie domain (usually: .yourdomain.com)
62 :param string $path: Cookie path
63 :param string $prefix: Cookie name prefix
64 :rtype: void
Derek Jones8ede1a22011-10-05 13:34:52 -050065
Derek Jonesb55d9812013-07-20 08:49:25 -070066 Lets you delete a cookie. Unless you've set a custom path or other
67 values, only the name of the cookie is needed.
Derek Jonesb55d9812013-07-20 08:49:25 -070068 ::
Derek Jones8ede1a22011-10-05 13:34:52 -050069
Derek Jonesb55d9812013-07-20 08:49:25 -070070 delete_cookie('name');
Derek Jones8ede1a22011-10-05 13:34:52 -050071
Derek Jonesb55d9812013-07-20 08:49:25 -070072 This function is otherwise identical to ``set_cookie()``, except that it
73 does not have the value and expiration parameters. You can submit an
74 array of values in the first parameter or you can set discrete
75 parameters.
Derek Jonesb55d9812013-07-20 08:49:25 -070076 ::
Derek Jones8ede1a22011-10-05 13:34:52 -050077
Derek Jonesb55d9812013-07-20 08:49:25 -070078 delete_cookie($name, $domain, $path, $prefix)