blob: c1469a9e9da5eace2fcc5c38e187acbfa8eed9f8 [file] [log] [blame]
Derek Allardd2df9bc2007-04-15 17:41:17 +00001<?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 Allard3d879d52008-01-18 19:41:32 +00008 * @author ExpressionEngine Dev Team
Derek Allardd2df9bc2007-04-15 17:41:17 +00009 * @copyright Copyright (c) 2006, EllisLab, Inc.
Derek Allard6838f002007-10-04 19:29:59 +000010 * @license http://www.codeigniter.com/user_guide/license.html
Derek Allardd2df9bc2007-04-15 17:41:17 +000011 * @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
Derek Allard3d879d52008-01-18 19:41:32 +000024 * @author ExpressionEngine Dev Team
Derek Allardd2df9bc2007-04-15 17:41:17 +000025 * @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 */
45function 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 Ellis7aa18092007-07-19 00:13:13 +000063 $prefix = $CI->config->item('cookie_prefix');
Derek Allardd2df9bc2007-04-15 17:41:17 +000064 }
65 if ($domain == '' AND $CI->config->item('cookie_domain') != '')
66 {
Rick Ellis7aa18092007-07-19 00:13:13 +000067 $domain = $CI->config->item('cookie_domain');
Derek Allardd2df9bc2007-04-15 17:41:17 +000068 }
Rick Ellis7aa18092007-07-19 00:13:13 +000069 if ($path == '/' AND $CI->config->item('cookie_path') != '/')
Derek Allardd2df9bc2007-04-15 17:41:17 +000070 {
Rick Ellis7aa18092007-07-19 00:13:13 +000071 $path = $CI->config->item('cookie_path');
Derek Allardd2df9bc2007-04-15 17:41:17 +000072 }
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 */
103function 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 */
120function delete_cookie($name = '', $domain = '', $path = '/', $prefix = '')
121{
122 set_cookie($name, '', '', $domain, $path, $prefix);
123}
124
125
adminb0dd10f2006-08-25 17:25:49 +0000126?>