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 | 422b889 | 2017-02-01 14:36:49 +0200 | [diff] [blame] | 28 | .. php:function:: set_cookie($name[, $value = ''[, $expire = ''[, $domain = ''[, $path = '/'[, $prefix = ''[, $secure = NULL[, $httponly = NULL]]]]]]]) |
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 | |
Andrey Andreev | b4834cc | 2015-01-29 13:52:44 +0200 | [diff] [blame] | 40 | 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 Jones | b55d981 | 2013-07-20 08:49:25 -0700 | [diff] [blame] | 43 | ``CI_Input::set_cookie()``. |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 44 | |
Andrey Andreev | 3e75ff6 | 2015-12-10 13:28:19 +0200 | [diff] [blame] | 45 | .. php:function:: get_cookie($index[, $xss_clean = NULL]) |
Andrey Andreev | 48a8675 | 2012-11-08 15:16:34 +0200 | [diff] [blame] | 46 | |
Andrey Andreev | 3de130c | 2014-02-07 23:31:49 +0200 | [diff] [blame] | 47 | :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 Andreev | 48a8675 | 2012-11-08 15:16:34 +0200 | [diff] [blame] | 51 | |
Andrey Andreev | b4834cc | 2015-01-29 13:52:44 +0200 | [diff] [blame] | 52 | 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 Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 58 | |
Andrey Andreev | 3e75ff6 | 2015-12-10 13:28:19 +0200 | [diff] [blame] | 59 | .. php:function:: delete_cookie($name[, $domain = ''[, $path = '/'[, $prefix = '']]]) |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 60 | |
Andrey Andreev | 3de130c | 2014-02-07 23:31:49 +0200 | [diff] [blame] | 61 | :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 Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 66 | |
Derek Jones | b55d981 | 2013-07-20 08:49:25 -0700 | [diff] [blame] | 67 | 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 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 | b55d981 | 2013-07-20 08:49:25 -0700 | [diff] [blame] | 77 | :: |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 78 | |
Andrey Andreev | b4834cc | 2015-01-29 13:52:44 +0200 | [diff] [blame] | 79 | delete_cookie($name, $domain, $path, $prefix); |