blob: 2ad51e78ccd9252b946e0d1f4de665c7416d3eb8 [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 Andreev422b8892017-02-01 14:36:49 +020028.. php:function:: set_cookie($name[, $value = ''[, $expire = ''[, $domain = ''[, $path = '/'[, $prefix = ''[, $secure = NULL[, $httponly = NULL]]]]]]])
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
Andrey Andreevb4834cc2015-01-29 13:52:44 +020040 This helper function gives you friendlier syntax to set browser
41 cookies. Refer to the :doc:`Input Library <../libraries/input>` for
42 a description of its use, as this function is an alias for
Derek Jonesb55d9812013-07-20 08:49:25 -070043 ``CI_Input::set_cookie()``.
Derek Jones8ede1a22011-10-05 13:34:52 -050044
Andrey Andreev3e75ff62015-12-10 13:28:19 +020045.. php:function:: get_cookie($index[, $xss_clean = NULL])
Andrey Andreev48a86752012-11-08 15:16:34 +020046
Andrey Andreev3de130c2014-02-07 23:31:49 +020047 :param string $index: Cookie name
48 :param bool $xss_clean: Whether to apply XSS filtering to the returned value
49 :returns: The cookie value or NULL if not found
50 :rtype: mixed
Andrey Andreev48a86752012-11-08 15:16:34 +020051
Andrey Andreevb4834cc2015-01-29 13:52:44 +020052 This helper function gives you friendlier syntax to get browser
53 cookies. Refer to the :doc:`Input Library <../libraries/input>` for
54 detailed description of its use, as this function acts very
55 similarly to ``CI_Input::cookie()``, except it will also prepend
56 the ``$config['cookie_prefix']`` that you might've set in your
57 *application/config/config.php* file.
Derek Jones8ede1a22011-10-05 13:34:52 -050058
Andrey Andreev3e75ff62015-12-10 13:28:19 +020059.. php:function:: delete_cookie($name[, $domain = ''[, $path = '/'[, $prefix = '']]])
Derek Jones8ede1a22011-10-05 13:34:52 -050060
Andrey Andreev3de130c2014-02-07 23:31:49 +020061 :param string $name: Cookie name
62 :param string $domain: Cookie domain (usually: .yourdomain.com)
63 :param string $path: Cookie path
64 :param string $prefix: Cookie name prefix
65 :rtype: void
Derek Jones8ede1a22011-10-05 13:34:52 -050066
Derek Jonesb55d9812013-07-20 08:49:25 -070067 Lets you delete a cookie. Unless you've set a custom path or other
68 values, only the name of the cookie is needed.
Derek Jonesb55d9812013-07-20 08:49:25 -070069 ::
Derek Jones8ede1a22011-10-05 13:34:52 -050070
Derek Jonesb55d9812013-07-20 08:49:25 -070071 delete_cookie('name');
Derek Jones8ede1a22011-10-05 13:34:52 -050072
Derek Jonesb55d9812013-07-20 08:49:25 -070073 This function is otherwise identical to ``set_cookie()``, except that it
74 does not have the value and expiration parameters. You can submit an
75 array of values in the first parameter or you can set discrete
76 parameters.
Derek Jonesb55d9812013-07-20 08:49:25 -070077 ::
Derek Jones8ede1a22011-10-05 13:34:52 -050078
Andrey Andreevb4834cc2015-01-29 13:52:44 +020079 delete_cookie($name, $domain, $path, $prefix);