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 | |
| 8 | .. contents:: Page Contents |
| 9 | |
| 10 | Loading this Helper |
| 11 | =================== |
| 12 | |
Andrey Andreev | 48a8675 | 2012-11-08 15:16:34 +0200 | [diff] [blame^] | 13 | This helper is loaded using the following code:: |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 14 | |
| 15 | $this->load->helper('cookie'); |
| 16 | |
| 17 | The following functions are available: |
| 18 | |
| 19 | set_cookie() |
| 20 | ============ |
| 21 | |
Andrey Andreev | 48a8675 | 2012-11-08 15:16:34 +0200 | [diff] [blame^] | 22 | .. php:function:: set_cookie($name = '', $value = '', $expire = '', $domain = '', $path = '/', $prefix = '', $secure = FALSE, $httponly = FALSE) |
| 23 | |
| 24 | :param string $name: Cookie name |
| 25 | :param string $value: Cookie value |
| 26 | :param int $expire: Number of seconds until expiration |
| 27 | :param string $domain: Cookie domain (usually: .yourdomain.com) |
| 28 | :param string $path: Cookie path |
| 29 | :param string $prefix: Cookie name prefix |
| 30 | :param bool $secure: Whether to only send the cookie through HTTPS |
| 31 | :param bool $httponly: Whether to hide the cookie from JavaScript |
| 32 | :returns: void |
| 33 | |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 34 | This helper function gives you view file friendly syntax to set browser |
Andrey Andreev | 48a8675 | 2012-11-08 15:16:34 +0200 | [diff] [blame^] | 35 | cookies. Refer to the :doc:`Input Library <../libraries/input>` for a |
| 36 | description of its use, as this function is an alias for |
| 37 | ``CI_Input::set_cookie()``. |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 38 | |
| 39 | get_cookie() |
| 40 | ============ |
| 41 | |
Andrey Andreev | 48a8675 | 2012-11-08 15:16:34 +0200 | [diff] [blame^] | 42 | .. php:function:: get_cookie($index = '', $xss_clean = FALSE) |
| 43 | |
| 44 | :param string $index: Cookie name |
| 45 | :param bool $xss_clean: Whether to apply XSS filtering to the returned value |
| 46 | :returns: mixed |
| 47 | |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 48 | This helper function gives you view file friendly syntax to get browser |
Andrey Andreev | 48a8675 | 2012-11-08 15:16:34 +0200 | [diff] [blame^] | 49 | cookies. Refer to the :doc:`Input Library <../libraries/input>` for a |
| 50 | description of itsuse, as this function is an alias for ``CI_Input::cookie()``. |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 51 | |
| 52 | delete_cookie() |
| 53 | =============== |
| 54 | |
Andrey Andreev | 48a8675 | 2012-11-08 15:16:34 +0200 | [diff] [blame^] | 55 | .. php:function:: delete_cookie($name = '', $domain = '', $path = '/', $prefix = '') |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 56 | |
Andrey Andreev | 48a8675 | 2012-11-08 15:16:34 +0200 | [diff] [blame^] | 57 | :param string $name: Cookie name |
| 58 | :param string $domain: Cookie domain (usually: .yourdomain.com) |
| 59 | :param string $path: Cookie path |
| 60 | :param string $prefix: Cookie name prefix |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 61 | :returns: void |
| 62 | |
Andrey Andreev | 48a8675 | 2012-11-08 15:16:34 +0200 | [diff] [blame^] | 63 | Lets you delete a cookie. Unless you've set a custom path or other |
| 64 | values, only the name of the cookie is needed. |
| 65 | |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 66 | :: |
| 67 | |
Andrey Andreev | 48a8675 | 2012-11-08 15:16:34 +0200 | [diff] [blame^] | 68 | delete_cookie('name'); |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 69 | |
| 70 | This function is otherwise identical to ``set_cookie()``, except that it |
| 71 | does not have the value and expiration parameters. You can submit an |
| 72 | array of values in the first parameter or you can set discrete |
| 73 | parameters. |
| 74 | |
| 75 | :: |
| 76 | |
| 77 | delete_cookie($name, $domain, $path, $prefix) |