Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 1 | <?php if (!defined('BASEPATH')) exit('No direct script access allowed');
|
| 2 | /**
|
| 3 | * CodeIgniter
|
| 4 | *
|
| 5 | * An open source application development framework for PHP 4.3.2 or newer
|
| 6 | *
|
| 7 | * @package CodeIgniter
|
Derek Allard | 3d879d5 | 2008-01-18 19:41:32 +0000 | [diff] [blame] | 8 | * @author ExpressionEngine Dev Team
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 9 | * @copyright Copyright (c) 2006, EllisLab, Inc.
|
Derek Jones | 7a9193a | 2008-01-21 18:39:20 +0000 | [diff] [blame] | 10 | * @license http://codeigniter.com/user_guide/license.html
|
| 11 | * @link http://codeigniter.com
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 12 | * @since Version 1.0
|
| 13 | * @filesource
|
| 14 | */
|
| 15 |
|
| 16 | // ------------------------------------------------------------------------
|
| 17 |
|
| 18 | /**
|
| 19 | * CodeIgniter Cookie Helpers
|
| 20 | *
|
| 21 | * @package CodeIgniter
|
| 22 | * @subpackage Helpers
|
| 23 | * @category Helpers
|
Derek Allard | 3d879d5 | 2008-01-18 19:41:32 +0000 | [diff] [blame] | 24 | * @author ExpressionEngine Dev Team
|
Derek Jones | 7a9193a | 2008-01-21 18:39:20 +0000 | [diff] [blame] | 25 | * @link http://codeigniter.com/user_guide/helpers/cookie_helper.html
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 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 | */
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 45 | if (! function_exists('set_cookie'))
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 46 | {
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 47 | function set_cookie($name = '', $value = '', $expire = '', $domain = '', $path = '/', $prefix = '')
|
| 48 | {
|
| 49 | if (is_array($name))
|
| 50 | {
|
| 51 | foreach (array('value', 'expire', 'domain', 'path', 'prefix', 'name') as $item)
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 52 | {
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 53 | if (isset($name[$item]))
|
| 54 | {
|
| 55 | $$item = $name[$item];
|
| 56 | }
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 57 | }
|
| 58 | }
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 59 |
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 60 | // Set the config file options
|
| 61 | $CI =& get_instance();
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 62 |
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 63 | if ($prefix == '' AND $CI->config->item('cookie_prefix') != '')
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 64 | {
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 65 | $prefix = $CI->config->item('cookie_prefix');
|
| 66 | }
|
| 67 | if ($domain == '' AND $CI->config->item('cookie_domain') != '')
|
| 68 | {
|
| 69 | $domain = $CI->config->item('cookie_domain');
|
| 70 | }
|
| 71 | if ($path == '/' AND $CI->config->item('cookie_path') != '/')
|
| 72 | {
|
| 73 | $path = $CI->config->item('cookie_path');
|
| 74 | }
|
| 75 |
|
Derek Allard | 7327499 | 2008-05-05 16:39:18 +0000 | [diff] [blame] | 76 | if (! is_numeric($expire))
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 77 | {
|
| 78 | $expire = time() - 86500;
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 79 | }
|
| 80 | else
|
| 81 | {
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 82 | if ($expire > 0)
|
| 83 | {
|
| 84 | $expire = time() + $expire;
|
| 85 | }
|
| 86 | else
|
| 87 | {
|
| 88 | $expire = 0;
|
| 89 | }
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 90 | }
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 91 |
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 92 | setcookie($prefix.$name, $value, $expire, $path, $domain, 0);
|
| 93 | }
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 94 | }
|
| 95 |
|
| 96 | // --------------------------------------------------------------------
|
| 97 |
|
| 98 | /**
|
| 99 | * Fetch an item from the COOKIE array
|
| 100 | *
|
| 101 | * @access public
|
| 102 | * @param string
|
| 103 | * @param bool
|
| 104 | * @return mixed
|
| 105 | */
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 106 | if (! function_exists('get_cookie'))
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 107 | {
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 108 | function get_cookie($index = '', $xss_clean = FALSE)
|
| 109 | {
|
| 110 | $CI =& get_instance();
|
| 111 | return $CI->input->cookie($index, $xss_clean);
|
| 112 | }
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 113 | }
|
| 114 |
|
| 115 | // --------------------------------------------------------------------
|
| 116 |
|
| 117 | /**
|
| 118 | * Delete a COOKIE
|
| 119 | *
|
| 120 | * @param mixed
|
| 121 | * @param string the cookie domain. Usually: .yourdomain.com
|
| 122 | * @param string the cookie path
|
| 123 | * @param string the cookie prefix
|
| 124 | * @return void
|
| 125 | */
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 126 | if (! function_exists('delete_cookie'))
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 127 | {
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 128 | function delete_cookie($name = '', $domain = '', $path = '/', $prefix = '')
|
| 129 | {
|
| 130 | set_cookie($name, '', '', $domain, $path, $prefix);
|
| 131 | }
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 132 | }
|
| 133 |
|
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 134 | ?> |