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
|
| 8 | * @author Rick Ellis
|
| 9 | * @copyright Copyright (c) 2006, EllisLab, 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 | * CodeIgniter 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 |
|
| 58 | // Set the config file options
|
| 59 | $CI =& get_instance();
|
| 60 |
|
| 61 | if ($prefix == '' AND $CI->config->item('cookie_prefix') != '')
|
| 62 | {
|
Rick Ellis | 7aa1809 | 2007-07-19 00:13:13 +0000 | [diff] [blame] | 63 | $prefix = $CI->config->item('cookie_prefix');
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 64 | }
|
| 65 | if ($domain == '' AND $CI->config->item('cookie_domain') != '')
|
| 66 | {
|
Rick Ellis | 7aa1809 | 2007-07-19 00:13:13 +0000 | [diff] [blame] | 67 | $domain = $CI->config->item('cookie_domain');
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 68 | }
|
Rick Ellis | 7aa1809 | 2007-07-19 00:13:13 +0000 | [diff] [blame] | 69 | if ($path == '/' AND $CI->config->item('cookie_path') != '/')
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 70 | {
|
Rick Ellis | 7aa1809 | 2007-07-19 00:13:13 +0000 | [diff] [blame] | 71 | $path = $CI->config->item('cookie_path');
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 72 | }
|
| 73 |
|
| 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 | }
|
| 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 | $CI =& get_instance();
|
| 106 | return $CI->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 |
|
| 125 |
|
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 126 | ?> |