Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 1 | ############# |
| 2 | Cookie Helper |
| 3 | ############# |
| 4 | |
| 5 | The Cookie Helper file contains functions that assist in working with |
| 6 | cookies. |
| 7 | |
Derek Jones | b55d981 | 2013-07-20 08:49:25 -0700 | [diff] [blame] | 8 | .. contents:: |
| 9 | :local: |
| 10 | |
| 11 | .. raw:: html |
| 12 | |
| 13 | <div class="custom-index container"></div> |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 14 | |
| 15 | Loading this Helper |
| 16 | =================== |
| 17 | |
Andrey Andreev | 48a8675 | 2012-11-08 15:16:34 +0200 | [diff] [blame] | 18 | This helper is loaded using the following code:: |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 19 | |
| 20 | $this->load->helper('cookie'); |
| 21 | |
Derek Jones | b55d981 | 2013-07-20 08:49:25 -0700 | [diff] [blame] | 22 | Available Functions |
| 23 | =================== |
| 24 | |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 25 | The following functions are available: |
| 26 | |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 27 | |
Andrey Andreev | 04535c7 | 2014-01-06 10:57:05 +0200 | [diff] [blame] | 28 | .. function:: set_cookie($name[, $value = ''[, $expire = ''[, $domain = ''[, $path = '/'[, $prefix = ''[, $secure = FALSE[, $httponly = FALSE]]]]]]]]) |
Andrey Andreev | 48a8675 | 2012-11-08 15:16:34 +0200 | [diff] [blame] | 29 | |
Andrey Andreev | 3de130c | 2014-02-07 23:31:49 +0200 | [diff] [blame] | 30 | :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 Andreev | 48a8675 | 2012-11-08 15:16:34 +0200 | [diff] [blame] | 39 | |
Derek Jones | b55d981 | 2013-07-20 08:49:25 -0700 | [diff] [blame] | 40 | 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 Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 44 | |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 45 | |
Andrey Andreev | 88ebdf7 | 2014-01-08 17:28:02 +0200 | [diff] [blame] | 46 | .. function:: get_cookie($index[, $xss_clean = NULL]]) |
Andrey Andreev | 48a8675 | 2012-11-08 15:16:34 +0200 | [diff] [blame] | 47 | |
Andrey Andreev | 3de130c | 2014-02-07 23:31:49 +0200 | [diff] [blame] | 48 | :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 Andreev | 48a8675 | 2012-11-08 15:16:34 +0200 | [diff] [blame] | 52 | |
Derek Jones | b55d981 | 2013-07-20 08:49:25 -0700 | [diff] [blame] | 53 | 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 Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 56 | |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 57 | |
Andrey Andreev | 04535c7 | 2014-01-06 10:57:05 +0200 | [diff] [blame] | 58 | .. function:: delete_cookie($name[, $domain = ''[, $path = '/'[, $prefix = '']]]]) |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 59 | |
Andrey Andreev | 3de130c | 2014-02-07 23:31:49 +0200 | [diff] [blame] | 60 | :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 Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 65 | |
Derek Jones | b55d981 | 2013-07-20 08:49:25 -0700 | [diff] [blame] | 66 | 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 Jones | b55d981 | 2013-07-20 08:49:25 -0700 | [diff] [blame] | 68 | :: |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 69 | |
Derek Jones | b55d981 | 2013-07-20 08:49:25 -0700 | [diff] [blame] | 70 | delete_cookie('name'); |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 71 | |
Derek Jones | b55d981 | 2013-07-20 08:49:25 -0700 | [diff] [blame] | 72 | 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 Jones | b55d981 | 2013-07-20 08:49:25 -0700 | [diff] [blame] | 76 | :: |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 77 | |
Derek Jones | b55d981 | 2013-07-20 08:49:25 -0700 | [diff] [blame] | 78 | delete_cookie($name, $domain, $path, $prefix) |