Subversion-Projekte lars-tiefland.codeigniter

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 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		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
 */
45
if ( ! 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
 */
106
if ( ! function_exists('get_cookie'))
107
{
108
	function get_cookie($index = '', $xss_clean = FALSE)
109
	{
110
		$CI =& get_instance();
111
 
112
		$prefix = '';
113
 
114
		if ( ! isset($_COOKIE[$index]) && config_item('cookie_prefix') != '')
115
		{
116
			$prefix = config_item('cookie_prefix');
117
		}
118
 
119
		return $CI->input->cookie($prefix.$index, $xss_clean);
120
	}
121
}
122
 
123
// --------------------------------------------------------------------
124
 
125
/**
126
 * Delete a COOKIE
127
 *
128
 * @param	mixed
129
 * @param	string	the cookie domain.  Usually:  .yourdomain.com
130
 * @param	string	the cookie path
131
 * @param	string	the cookie prefix
132
 * @return	void
133
 */
134
if ( ! function_exists('delete_cookie'))
135
{
136
	function delete_cookie($name = '', $domain = '', $path = '/', $prefix = '')
137
	{
138
		set_cookie($name, '', '', $domain, $path, $prefix);
139
	}
140
}
141
 
142
 
143
/* End of file cookie_helper.php */
144
/* Location: ./system/helpers/cookie_helper.php */