blob: 82162264995d4357a60377d8678ef38cae75c5fe [file] [log] [blame]
Derek Jones0b59f272008-05-13 04:22:33 +00001<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
Derek Allardd2df9bc2007-04-15 17:41:17 +00002/**
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 Jones7a9193a2008-01-21 18:39:20 +000010 * @license http://codeigniter.com/user_guide/license.html
11 * @link http://codeigniter.com
Derek Allardd2df9bc2007-04-15 17:41:17 +000012 * @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 Jones7a9193a2008-01-21 18:39:20 +000025 * @link http://codeigniter.com/user_guide/helpers/cookie_helper.html
Derek Allardd2df9bc2007-04-15 17:41:17 +000026 */
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 Jones0b59f272008-05-13 04:22:33 +000045if ( ! function_exists('set_cookie'))
Derek Allardd2df9bc2007-04-15 17:41:17 +000046{
Derek Jones269b9422008-01-28 21:00:20 +000047 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 Allardd2df9bc2007-04-15 17:41:17 +000052 {
Derek Jones269b9422008-01-28 21:00:20 +000053 if (isset($name[$item]))
54 {
55 $$item = $name[$item];
56 }
Derek Allardd2df9bc2007-04-15 17:41:17 +000057 }
58 }
Derek Allardd2df9bc2007-04-15 17:41:17 +000059
Derek Jones269b9422008-01-28 21:00:20 +000060 // Set the config file options
61 $CI =& get_instance();
Derek Allardd2df9bc2007-04-15 17:41:17 +000062
Derek Jones269b9422008-01-28 21:00:20 +000063 if ($prefix == '' AND $CI->config->item('cookie_prefix') != '')
Derek Allardd2df9bc2007-04-15 17:41:17 +000064 {
Derek Jones269b9422008-01-28 21:00:20 +000065 $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 Jones0b59f272008-05-13 04:22:33 +000076 if ( ! is_numeric($expire))
Derek Jones269b9422008-01-28 21:00:20 +000077 {
78 $expire = time() - 86500;
Derek Allardd2df9bc2007-04-15 17:41:17 +000079 }
80 else
81 {
Derek Jones269b9422008-01-28 21:00:20 +000082 if ($expire > 0)
83 {
84 $expire = time() + $expire;
85 }
86 else
87 {
88 $expire = 0;
89 }
Derek Allardd2df9bc2007-04-15 17:41:17 +000090 }
Derek Allardd2df9bc2007-04-15 17:41:17 +000091
Derek Jones269b9422008-01-28 21:00:20 +000092 setcookie($prefix.$name, $value, $expire, $path, $domain, 0);
93 }
Derek Allardd2df9bc2007-04-15 17:41:17 +000094}
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 Jones0b59f272008-05-13 04:22:33 +0000106if ( ! function_exists('get_cookie'))
Derek Allardd2df9bc2007-04-15 17:41:17 +0000107{
Derek Jones269b9422008-01-28 21:00:20 +0000108 function get_cookie($index = '', $xss_clean = FALSE)
109 {
110 $CI =& get_instance();
111 return $CI->input->cookie($index, $xss_clean);
112 }
Derek Allardd2df9bc2007-04-15 17:41:17 +0000113}
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 Jones0b59f272008-05-13 04:22:33 +0000126if ( ! function_exists('delete_cookie'))
Derek Allardd2df9bc2007-04-15 17:41:17 +0000127{
Derek Jones269b9422008-01-28 21:00:20 +0000128 function delete_cookie($name = '', $domain = '', $path = '/', $prefix = '')
129 {
130 set_cookie($name, '', '', $domain, $path, $prefix);
131 }
Derek Allardd2df9bc2007-04-15 17:41:17 +0000132}
133
Derek Jones0b59f272008-05-13 04:22:33 +0000134
135/* End of file cookie_helper.php */
Derek Jonesa3ffbbb2008-05-11 18:18:29 +0000136/* Location: ./system/helpers/cookie_helper.php */