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 | |
Derek Jones | 26f7a9f | 2013-07-20 09:00:02 -0700 | [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 | |
Derek Jones | b55d981 | 2013-07-20 08:49:25 -0700 | [diff] [blame] | 30 | :param mixed $name: Cookie name *or* associative array of all of |
| 31 | the parameters available to this function |
Andrey Andreev | 48a8675 | 2012-11-08 15:16:34 +0200 | [diff] [blame] | 32 | :param string $value: Cookie value |
| 33 | :param int $expire: Number of seconds until expiration |
| 34 | :param string $domain: Cookie domain (usually: .yourdomain.com) |
| 35 | :param string $path: Cookie path |
| 36 | :param string $prefix: Cookie name prefix |
| 37 | :param bool $secure: Whether to only send the cookie through HTTPS |
| 38 | :param bool $httponly: Whether to hide the cookie from JavaScript |
| 39 | :returns: void |
| 40 | |
Derek Jones | b55d981 | 2013-07-20 08:49:25 -0700 | [diff] [blame] | 41 | This helper function gives you view file friendly syntax to set browser |
| 42 | cookies. Refer to the :doc:`Input Library <../libraries/input>` for a |
| 43 | description of its use, as this function is an alias for |
| 44 | ``CI_Input::set_cookie()``. |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 45 | |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 46 | |
Derek Jones | 26f7a9f | 2013-07-20 09:00:02 -0700 | [diff] [blame^] | 47 | .. function:: get_cookie([$index = ''[, $xss_clean = FALSE]]) |
Andrey Andreev | 48a8675 | 2012-11-08 15:16:34 +0200 | [diff] [blame] | 48 | |
| 49 | :param string $index: Cookie name |
| 50 | :param bool $xss_clean: Whether to apply XSS filtering to the returned value |
| 51 | :returns: mixed |
| 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 | |
Derek Jones | 26f7a9f | 2013-07-20 09:00:02 -0700 | [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 | 48a8675 | 2012-11-08 15:16:34 +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 |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 64 | :returns: void |
| 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. |
Andrey Andreev | 48a8675 | 2012-11-08 15:16:34 +0200 | [diff] [blame] | 68 | |
Derek Jones | b55d981 | 2013-07-20 08:49:25 -0700 | [diff] [blame] | 69 | :: |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 70 | |
Derek Jones | b55d981 | 2013-07-20 08:49:25 -0700 | [diff] [blame] | 71 | delete_cookie('name'); |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 72 | |
Derek Jones | b55d981 | 2013-07-20 08:49:25 -0700 | [diff] [blame] | 73 | 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 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 | :: |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 79 | |
Derek Jones | b55d981 | 2013-07-20 08:49:25 -0700 | [diff] [blame] | 80 | delete_cookie($name, $domain, $path, $prefix) |