admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 1 | <?php if (!defined('BASEPATH')) exit('No direct script access allowed'); |
| 2 | /** |
| 3 | * Code Igniter |
| 4 | * |
| 5 | * An open source application development framework for PHP 4.3.2 or newer |
| 6 | * |
| 7 | * @package CodeIgniter |
| 8 | * @author Rick Ellis |
| 9 | * @copyright Copyright (c) 2006, pMachine, Inc. |
| 10 | * @license http://www.codeignitor.com/user_guide/license.html |
| 11 | * @link http://www.codeigniter.com |
| 12 | * @since Version 1.0 |
| 13 | * @filesource |
| 14 | */ |
| 15 | |
| 16 | // ------------------------------------------------------------------------ |
| 17 | |
| 18 | /** |
| 19 | * Code Igniter Cookie Helpers |
| 20 | * |
| 21 | * @package CodeIgniter |
| 22 | * @subpackage Helpers |
| 23 | * @category Helpers |
| 24 | * @author Rick Ellis |
| 25 | * @link http://www.codeigniter.com/user_guide/helpers/cookie_helper.html |
| 26 | */ |
| 27 | |
| 28 | // ------------------------------------------------------------------------ |
| 29 | |
| 30 | /** |
| 31 | * Set cookie |
| 32 | * |
| 33 | * Accepts six parameter, or you can submit an associative |
| 34 | * array in the first parameter containing all the values. |
| 35 | * |
| 36 | * @access public |
| 37 | * @param mixed |
| 38 | * @param string the value of the cookie |
| 39 | * @param string the number of seconds until expiration |
| 40 | * @param string the cookie domain. Usually: .yourdomain.com |
| 41 | * @param string the cookie path |
| 42 | * @param string the cookie prefix |
| 43 | * @return void |
| 44 | */ |
| 45 | function set_cookie($name = '', $value = '', $expire = '', $domain = '', $path = '/', $prefix = '') |
| 46 | { |
| 47 | if (is_array($name)) |
| 48 | { |
| 49 | foreach (array('value', 'expire', 'domain', 'path', 'prefix', 'name') as $item) |
| 50 | { |
| 51 | if (isset($name[$item])) |
| 52 | { |
| 53 | $$item = $name[$item]; |
| 54 | } |
| 55 | } |
| 56 | } |
| 57 | |
admin | 885b034 | 2006-09-21 05:36:15 +0000 | [diff] [blame^] | 58 | // Set the config file options |
| 59 | $obj =& get_instance(); |
| 60 | |
| 61 | if ($prefix == '' AND $obj->config->item('cookie_prefix') != '') |
| 62 | { |
| 63 | $obj->config->item('cookie_prefix'); |
| 64 | } |
| 65 | if ($domain == '' AND $obj->config->item('cookie_domain') != '') |
| 66 | { |
| 67 | $obj->config->item('cookie_domain'); |
| 68 | } |
| 69 | if ($prefix == '/' AND $obj->config->item('cookie_path') != '/') |
| 70 | { |
| 71 | $obj->config->item('cookie_path'); |
| 72 | } |
| 73 | |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 74 | if ( ! is_numeric($expire)) |
| 75 | { |
| 76 | $expire = time() - 86500; |
| 77 | } |
| 78 | else |
| 79 | { |
| 80 | if ($expire > 0) |
| 81 | { |
| 82 | $expire = time() + $expire; |
| 83 | } |
| 84 | else |
| 85 | { |
| 86 | $expire = 0; |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | setcookie($prefix.$name, $value, $expire, $path, $domain, 0); |
| 91 | } |
admin | 885b034 | 2006-09-21 05:36:15 +0000 | [diff] [blame^] | 92 | |
| 93 | // -------------------------------------------------------------------- |
| 94 | |
| 95 | /** |
| 96 | * Fetch an item from the COOKIE array |
| 97 | * |
| 98 | * @access public |
| 99 | * @param string |
| 100 | * @param bool |
| 101 | * @return mixed |
| 102 | */ |
| 103 | function get_cookie($index = '', $xss_clean = FALSE) |
| 104 | { |
| 105 | $obj =& get_instance(); |
| 106 | return $obj->input->cookie($index, $xss_clean); |
| 107 | } |
| 108 | |
| 109 | // -------------------------------------------------------------------- |
| 110 | |
| 111 | /** |
| 112 | * Delete a COOKIE |
| 113 | * |
| 114 | * @param mixed |
| 115 | * @param string the cookie domain. Usually: .yourdomain.com |
| 116 | * @param string the cookie path |
| 117 | * @param string the cookie prefix |
| 118 | * @return void |
| 119 | */ |
| 120 | function delete_cookie($name = '', $domain = '', $path = '/', $prefix = '') |
| 121 | { |
| 122 | set_cookie($name, '', '', $domain, $path, $prefix); |
| 123 | } |
| 124 | |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 125 | |
| 126 | ?> |