blob: 77f86e4891454e2f476d1db6767d8792b534e7a3 [file] [log] [blame]
Derek Allard2067d1a2008-11-13 22:59:24 +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
8 * @author ExpressionEngine Dev Team
9 * @copyright Copyright (c) 2008, EllisLab, Inc.
10 * @license http://codeigniter.com/user_guide/license.html
11 * @link http://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 ExpressionEngine Dev Team
25 * @link http://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 */
45if ( ! function_exists('set_cookie'))
46{
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)
52 {
53 if (isset($name[$item]))
54 {
55 $$item = $name[$item];
56 }
57 }
58 }
59
60 // Set the config file options
61 $CI =& get_instance();
62
63 if ($prefix == '' AND $CI->config->item('cookie_prefix') != '')
64 {
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
76 if ( ! is_numeric($expire))
77 {
78 $expire = time() - 86500;
79 }
80 else
81 {
82 if ($expire > 0)
83 {
84 $expire = time() + $expire;
85 }
86 else
87 {
88 $expire = 0;
89 }
90 }
91
92 setcookie($prefix.$name, $value, $expire, $path, $domain, 0);
93 }
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 */
106if ( ! function_exists('get_cookie'))
107{
108 function get_cookie($index = '', $xss_clean = FALSE)
109 {
Derek Jones2c8dc582009-02-10 20:15:49 +0000110 $prefix = '';
111
112 if ( ! isset($_COOKIE[$index]) && config_item('cookie_prefix') != '')
113 {
114 $prefix = config_item('cookie_prefix');
115 }
116
117 return $CI->input->cookie($prefix.$index, $xss_clean);
Derek Allard2067d1a2008-11-13 22:59:24 +0000118 }
119}
120
121// --------------------------------------------------------------------
122
123/**
124 * Delete a COOKIE
125 *
126 * @param mixed
127 * @param string the cookie domain. Usually: .yourdomain.com
128 * @param string the cookie path
129 * @param string the cookie prefix
130 * @return void
131 */
132if ( ! function_exists('delete_cookie'))
133{
134 function delete_cookie($name = '', $domain = '', $path = '/', $prefix = '')
135 {
136 set_cookie($name, '', '', $domain, $path, $prefix);
137 }
138}
139
140
141/* End of file cookie_helper.php */
Derek Jonesa3ffbbb2008-05-11 18:18:29 +0000142/* Location: ./system/helpers/cookie_helper.php */