Andrey Andreev | c5536aa | 2012-11-01 17:33:58 +0200 | [diff] [blame] | 1 | <?php |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 2 | /** |
| 3 | * CodeIgniter |
| 4 | * |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 5 | * An open source application development framework for PHP 5.2.4 or newer |
| 6 | * |
| 7 | * NOTICE OF LICENSE |
| 8 | * |
| 9 | * Licensed under the Open Software License version 3.0 |
| 10 | * |
| 11 | * This source file is subject to the Open Software License (OSL 3.0) that is |
| 12 | * bundled with this package in the files license.txt / license.rst. It is |
| 13 | * also available through the world wide web at this URL: |
| 14 | * http://opensource.org/licenses/OSL-3.0 |
| 15 | * If you did not receive a copy of the license and are unable to obtain it |
| 16 | * through the world wide web, please send an email to |
| 17 | * licensing@ellislab.com so we can send you a copy immediately. |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 18 | * |
| 19 | * @package CodeIgniter |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 20 | * @author EllisLab Dev Team |
Andrey Andreev | 80500af | 2013-01-01 08:16:53 +0200 | [diff] [blame] | 21 | * @copyright Copyright (c) 2008 - 2013, EllisLab, Inc. (http://ellislab.com/) |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 22 | * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 23 | * @link http://codeigniter.com |
| 24 | * @since Version 2.0 |
| 25 | * @filesource |
| 26 | */ |
Andrey Andreev | c5536aa | 2012-11-01 17:33:58 +0200 | [diff] [blame] | 27 | defined('BASEPATH') OR exit('No direct script access allowed'); |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 28 | |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 29 | /** |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 30 | * CodeIgniter Session Class |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 31 | * |
| 32 | * The user interface defined by EllisLabs, now with puggable drivers to manage different storage mechanisms. |
dchill42 | 0e88408 | 2012-08-11 20:10:17 -0400 | [diff] [blame] | 33 | * By default, the cookie session driver will load, but the 'sess_driver' config/param item (see above) can be |
| 34 | * used to specify the 'native' driver, or any other you might create. |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 35 | * Once loaded, this driver setup is a drop-in replacement for the former CI_Session library, taking its place as the |
| 36 | * 'session' member of the global controller framework (e.g.: $CI->session or $this->session). |
| 37 | * In keeping with the CI_Driver methodology, multiple drivers may be loaded, although this might be a bit confusing. |
Darren Hill | 5073a37 | 2011-08-31 13:54:19 -0400 | [diff] [blame] | 38 | * The CI_Session library class keeps track of the most recently loaded driver as "current" to call for driver methods. |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 39 | * Ideally, one driver is loaded and all calls go directly through the main library interface. However, any methods |
| 40 | * called through the specific driver will switch the "current" driver to itself before invoking the library method |
| 41 | * (which will then call back into the driver for low-level operations). So, alternation between two drivers can be |
| 42 | * achieved by specifying which driver to use for each call (e.g.: $this->session->native->set_userdata('foo', 'bar'); |
| 43 | * $this->session->cookie->userdata('foo'); $this->session->native->unset_userdata('foo');). Notice in the previous |
| 44 | * example that the _native_ userdata value 'foo' would be set to 'bar', which would NOT be returned by the call for |
| 45 | * the _cookie_ userdata 'foo', nor would the _cookie_ value be unset by the call to unset the _native_ 'foo' value. |
| 46 | * |
| 47 | * @package CodeIgniter |
| 48 | * @subpackage Libraries |
| 49 | * @category Sessions |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 50 | * @author EllisLab Dev Team |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 51 | * @link http://codeigniter.com/user_guide/libraries/sessions.html |
| 52 | */ |
Darren Hill | a2ae657 | 2011-09-01 07:36:26 -0400 | [diff] [blame] | 53 | class CI_Session extends CI_Driver_Library { |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 54 | |
Andrey Andreev | 0fa95bd | 2012-11-01 23:33:14 +0200 | [diff] [blame] | 55 | /** |
| 56 | * Initialization parameters |
| 57 | * |
| 58 | * @var array |
| 59 | */ |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 60 | public $params = array(); |
Andrey Andreev | 0fa95bd | 2012-11-01 23:33:14 +0200 | [diff] [blame] | 61 | |
| 62 | /** |
| 63 | * Current driver in use |
| 64 | * |
| 65 | * @var string |
| 66 | */ |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 67 | protected $current = NULL; |
Andrey Andreev | 0fa95bd | 2012-11-01 23:33:14 +0200 | [diff] [blame] | 68 | |
| 69 | /** |
| 70 | * User data |
| 71 | * |
| 72 | * @var array |
| 73 | */ |
Darren Hill | a2ae657 | 2011-09-01 07:36:26 -0400 | [diff] [blame] | 74 | protected $userdata = array(); |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 75 | |
Andrey Andreev | 0fa95bd | 2012-11-01 23:33:14 +0200 | [diff] [blame] | 76 | // ------------------------------------------------------------------------ |
| 77 | |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 78 | const FLASHDATA_KEY = 'flash'; |
| 79 | const FLASHDATA_NEW = ':new:'; |
| 80 | const FLASHDATA_OLD = ':old:'; |
| 81 | const FLASHDATA_EXP = ':exp:'; |
| 82 | const EXPIRATION_KEY = '__expirations'; |
| 83 | const TEMP_EXP_DEF = 300; |
| 84 | |
Andrey Andreev | 0fa95bd | 2012-11-01 23:33:14 +0200 | [diff] [blame] | 85 | // ------------------------------------------------------------------------ |
| 86 | |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 87 | /** |
Darren Hill | 5073a37 | 2011-08-31 13:54:19 -0400 | [diff] [blame] | 88 | * CI_Session constructor |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 89 | * |
| 90 | * The constructor loads the configured driver ('sess_driver' in config.php or as a parameter), running |
| 91 | * routines in its constructor, and manages flashdata aging. |
| 92 | * |
Darren Hill | 5073a37 | 2011-08-31 13:54:19 -0400 | [diff] [blame] | 93 | * @param array Configuration parameters |
Andrey Andreev | 2e3e230 | 2012-10-09 15:52:34 +0300 | [diff] [blame] | 94 | * @return void |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 95 | */ |
| 96 | public function __construct(array $params = array()) |
| 97 | { |
Andrey Andreev | 2e3e230 | 2012-10-09 15:52:34 +0300 | [diff] [blame] | 98 | $CI =& get_instance(); |
| 99 | |
| 100 | // No sessions under CLI |
| 101 | if ($CI->input->is_cli_request()) |
| 102 | { |
| 103 | return; |
| 104 | } |
| 105 | |
Darren Hill | 5073a37 | 2011-08-31 13:54:19 -0400 | [diff] [blame] | 106 | log_message('debug', 'CI_Session Class Initialized'); |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 107 | |
| 108 | // Get valid drivers list |
dchill42 | 2642920 | 2012-07-31 10:55:07 -0400 | [diff] [blame] | 109 | $this->valid_drivers = array( |
dchill42 | 6262d05 | 2012-11-24 18:41:13 -0500 | [diff] [blame] | 110 | 'native', |
| 111 | 'cookie' |
dchill42 | 2642920 | 2012-07-31 10:55:07 -0400 | [diff] [blame] | 112 | ); |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 113 | $key = 'sess_valid_drivers'; |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 114 | $drivers = isset($params[$key]) ? $params[$key] : $CI->config->item($key); |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 115 | if ($drivers) |
| 116 | { |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 117 | // Add driver names to valid list |
dchill42 | 6262d05 | 2012-11-24 18:41:13 -0500 | [diff] [blame] | 118 | foreach ((array) $drivers as $driver) |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 119 | { |
dchill42 | 77ee3fd | 2012-07-24 11:50:01 -0400 | [diff] [blame] | 120 | if ( ! in_array(strtolower($driver), array_map('strtolower', $this->valid_drivers))) |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 121 | { |
| 122 | $this->valid_drivers[] = $driver; |
| 123 | } |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | // Get driver to load |
| 128 | $key = 'sess_driver'; |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 129 | $driver = isset($params[$key]) ? $params[$key] : $CI->config->item($key); |
| 130 | if ( ! $driver) |
| 131 | { |
| 132 | $driver = 'cookie'; |
| 133 | } |
| 134 | |
dchill42 | 6262d05 | 2012-11-24 18:41:13 -0500 | [diff] [blame] | 135 | if ( ! in_array(strtolower($driver), array_map('strtolower', $this->valid_drivers))) |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 136 | { |
dchill42 | 6262d05 | 2012-11-24 18:41:13 -0500 | [diff] [blame] | 137 | $this->valid_drivers[] = $driver; |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 138 | } |
| 139 | |
| 140 | // Save a copy of parameters in case drivers need access |
| 141 | $this->params = $params; |
| 142 | |
| 143 | // Load driver and get array reference |
| 144 | $this->load_driver($driver); |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 145 | |
| 146 | // Delete 'old' flashdata (from last request) |
| 147 | $this->_flashdata_sweep(); |
| 148 | |
| 149 | // Mark all new flashdata as old (data will be deleted before next request) |
| 150 | $this->_flashdata_mark(); |
| 151 | |
| 152 | // Delete expired tempdata |
| 153 | $this->_tempdata_sweep(); |
| 154 | |
Darren Hill | 5073a37 | 2011-08-31 13:54:19 -0400 | [diff] [blame] | 155 | log_message('debug', 'CI_Session routines successfully run'); |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 156 | } |
| 157 | |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 158 | // ------------------------------------------------------------------------ |
| 159 | |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 160 | /** |
| 161 | * Loads session storage driver |
| 162 | * |
Darren Hill | 5073a37 | 2011-08-31 13:54:19 -0400 | [diff] [blame] | 163 | * @param string Driver classname |
| 164 | * @return object Loaded driver object |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 165 | */ |
| 166 | public function load_driver($driver) |
| 167 | { |
dchill42 | 2642920 | 2012-07-31 10:55:07 -0400 | [diff] [blame] | 168 | // Save reference to most recently loaded driver as library default and sync userdata |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 169 | $this->current = parent::load_driver($driver); |
dchill42 | b185537 | 2012-07-31 09:32:23 -0400 | [diff] [blame] | 170 | $this->userdata =& $this->current->get_userdata(); |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 171 | return $this->current; |
| 172 | } |
| 173 | |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 174 | // ------------------------------------------------------------------------ |
| 175 | |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 176 | /** |
| 177 | * Select default session storage driver |
| 178 | * |
dchill42 | 6262d05 | 2012-11-24 18:41:13 -0500 | [diff] [blame] | 179 | * @param string Driver name |
Darren Hill | 5073a37 | 2011-08-31 13:54:19 -0400 | [diff] [blame] | 180 | * @return void |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 181 | */ |
| 182 | public function select_driver($driver) |
| 183 | { |
| 184 | // Validate driver name |
dchill42 | 6262d05 | 2012-11-24 18:41:13 -0500 | [diff] [blame] | 185 | $prefix = (string) get_instance()->config->item('subclass_prefix'); |
| 186 | $child = strtolower(str_replace(array('CI_', $prefix, $this->lib_name.'_'), '', $driver)); |
| 187 | if (in_array($child, array_map('strtolower', $this->valid_drivers))) |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 188 | { |
dchill42 | b185537 | 2012-07-31 09:32:23 -0400 | [diff] [blame] | 189 | // See if driver is loaded |
dchill42 | b185537 | 2012-07-31 09:32:23 -0400 | [diff] [blame] | 190 | if (isset($this->$child)) |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 191 | { |
dchill42 | aee9265 | 2012-08-26 21:45:35 -0400 | [diff] [blame] | 192 | // See if driver is already current |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 193 | if ($this->$child !== $this->current) |
| 194 | { |
dchill42 | aee9265 | 2012-08-26 21:45:35 -0400 | [diff] [blame] | 195 | // Make driver current and sync userdata |
| 196 | $this->current = $this->$child; |
| 197 | $this->userdata =& $this->current->get_userdata(); |
| 198 | } |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 199 | } |
| 200 | else |
| 201 | { |
dchill42 | 2642920 | 2012-07-31 10:55:07 -0400 | [diff] [blame] | 202 | // Load new driver |
dchill42 | aee9265 | 2012-08-26 21:45:35 -0400 | [diff] [blame] | 203 | $this->load_driver($child); |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 204 | } |
| 205 | } |
| 206 | } |
| 207 | |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 208 | // ------------------------------------------------------------------------ |
| 209 | |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 210 | /** |
| 211 | * Destroy the current session |
| 212 | * |
Darren Hill | 5073a37 | 2011-08-31 13:54:19 -0400 | [diff] [blame] | 213 | * @return void |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 214 | */ |
| 215 | public function sess_destroy() |
| 216 | { |
| 217 | // Just call destroy on driver |
| 218 | $this->current->sess_destroy(); |
| 219 | } |
| 220 | |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 221 | // ------------------------------------------------------------------------ |
| 222 | |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 223 | /** |
| 224 | * Regenerate the current session |
| 225 | * |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 226 | * @param bool Destroy session data flag (default: false) |
Darren Hill | 5073a37 | 2011-08-31 13:54:19 -0400 | [diff] [blame] | 227 | * @return void |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 228 | */ |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 229 | public function sess_regenerate($destroy = FALSE) |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 230 | { |
dchill42 | 2642920 | 2012-07-31 10:55:07 -0400 | [diff] [blame] | 231 | // Call regenerate on driver and resync userdata |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 232 | $this->current->sess_regenerate($destroy); |
dchill42 | 2642920 | 2012-07-31 10:55:07 -0400 | [diff] [blame] | 233 | $this->userdata =& $this->current->get_userdata(); |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 234 | } |
| 235 | |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 236 | // ------------------------------------------------------------------------ |
| 237 | |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 238 | /** |
| 239 | * Fetch a specific item from the session array |
| 240 | * |
Darren Hill | 5073a37 | 2011-08-31 13:54:19 -0400 | [diff] [blame] | 241 | * @param string Item key |
dchill42 | c587225 | 2012-07-30 14:53:11 -0400 | [diff] [blame] | 242 | * @return string Item value or NULL if not found |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 243 | */ |
| 244 | public function userdata($item) |
| 245 | { |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 246 | return isset($this->userdata[$item]) ? $this->userdata[$item] : NULL; |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 247 | } |
| 248 | |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 249 | // ------------------------------------------------------------------------ |
| 250 | |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 251 | /** |
| 252 | * Fetch all session data |
| 253 | * |
| 254 | * @return array User data array |
| 255 | */ |
| 256 | public function all_userdata() |
| 257 | { |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 258 | return isset($this->userdata) ? $this->userdata : NULL; |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 259 | } |
| 260 | |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 261 | // ------------------------------------------------------------------------ |
| 262 | |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 263 | /** |
dchill42 | c5079de | 2012-07-23 10:53:47 -0400 | [diff] [blame] | 264 | * Fetch all flashdata |
| 265 | * |
vkeranov | 3bb4029 | 2012-10-27 18:47:26 +0300 | [diff] [blame] | 266 | * @return array Flash data array |
dchill42 | c5079de | 2012-07-23 10:53:47 -0400 | [diff] [blame] | 267 | */ |
| 268 | public function all_flashdata() |
| 269 | { |
| 270 | $out = array(); |
| 271 | |
| 272 | // loop through all userdata |
| 273 | foreach ($this->all_userdata() as $key => $val) |
| 274 | { |
dchill42 | c587225 | 2012-07-30 14:53:11 -0400 | [diff] [blame] | 275 | // if it contains flashdata, add it |
dchill42 | c5079de | 2012-07-23 10:53:47 -0400 | [diff] [blame] | 276 | if (strpos($key, self::FLASHDATA_KEY.self::FLASHDATA_OLD) !== FALSE) |
| 277 | { |
dchill42 | 2642920 | 2012-07-31 10:55:07 -0400 | [diff] [blame] | 278 | $key = str_replace(self::FLASHDATA_KEY.self::FLASHDATA_OLD, '', $key); |
dchill42 | c5079de | 2012-07-23 10:53:47 -0400 | [diff] [blame] | 279 | $out[$key] = $val; |
| 280 | } |
| 281 | } |
| 282 | return $out; |
| 283 | } |
| 284 | |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 285 | // ------------------------------------------------------------------------ |
| 286 | |
dchill42 | c5079de | 2012-07-23 10:53:47 -0400 | [diff] [blame] | 287 | /** |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 288 | * Add or change data in the "userdata" array |
| 289 | * |
Darren Hill | 5073a37 | 2011-08-31 13:54:19 -0400 | [diff] [blame] | 290 | * @param mixed Item name or array of items |
| 291 | * @param string Item value or empty string |
| 292 | * @return void |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 293 | */ |
| 294 | public function set_userdata($newdata = array(), $newval = '') |
| 295 | { |
| 296 | // Wrap params as array if singular |
| 297 | if (is_string($newdata)) |
| 298 | { |
| 299 | $newdata = array($newdata => $newval); |
| 300 | } |
| 301 | |
| 302 | // Set each name/value pair |
| 303 | if (count($newdata) > 0) |
| 304 | { |
| 305 | foreach ($newdata as $key => $val) |
| 306 | { |
| 307 | $this->userdata[$key] = $val; |
| 308 | } |
| 309 | } |
| 310 | |
| 311 | // Tell driver data changed |
| 312 | $this->current->sess_save(); |
| 313 | } |
| 314 | |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 315 | // ------------------------------------------------------------------------ |
| 316 | |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 317 | /** |
| 318 | * Delete a session variable from the "userdata" array |
| 319 | * |
Darren Hill | 5073a37 | 2011-08-31 13:54:19 -0400 | [diff] [blame] | 320 | * @param mixed Item name or array of item names |
| 321 | * @return void |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 322 | */ |
| 323 | public function unset_userdata($newdata = array()) |
| 324 | { |
| 325 | // Wrap single name as array |
| 326 | if (is_string($newdata)) |
| 327 | { |
| 328 | $newdata = array($newdata => ''); |
| 329 | } |
| 330 | |
| 331 | // Unset each item name |
| 332 | if (count($newdata) > 0) |
| 333 | { |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 334 | foreach (array_keys($newdata) as $key) |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 335 | { |
| 336 | unset($this->userdata[$key]); |
| 337 | } |
| 338 | } |
| 339 | |
| 340 | // Tell driver data changed |
| 341 | $this->current->sess_save(); |
| 342 | } |
| 343 | |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 344 | // ------------------------------------------------------------------------ |
| 345 | |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 346 | /** |
| 347 | * Determine if an item exists |
| 348 | * |
Darren Hill | 5073a37 | 2011-08-31 13:54:19 -0400 | [diff] [blame] | 349 | * @param string Item name |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 350 | * @return bool |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 351 | */ |
| 352 | public function has_userdata($item) |
| 353 | { |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 354 | return isset($this->userdata[$item]); |
| 355 | } |
| 356 | |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 357 | // ------------------------------------------------------------------------ |
| 358 | |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 359 | /** |
| 360 | * Add or change flashdata, only available until the next request |
| 361 | * |
Darren Hill | 5073a37 | 2011-08-31 13:54:19 -0400 | [diff] [blame] | 362 | * @param mixed Item name or array of items |
| 363 | * @param string Item value or empty string |
| 364 | * @return void |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 365 | */ |
| 366 | public function set_flashdata($newdata = array(), $newval = '') |
| 367 | { |
| 368 | // Wrap item as array if singular |
| 369 | if (is_string($newdata)) |
| 370 | { |
| 371 | $newdata = array($newdata => $newval); |
| 372 | } |
| 373 | |
| 374 | // Prepend each key name and set value |
| 375 | if (count($newdata) > 0) |
| 376 | { |
| 377 | foreach ($newdata as $key => $val) |
| 378 | { |
| 379 | $flashdata_key = self::FLASHDATA_KEY.self::FLASHDATA_NEW.$key; |
| 380 | $this->set_userdata($flashdata_key, $val); |
| 381 | } |
| 382 | } |
| 383 | } |
| 384 | |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 385 | // ------------------------------------------------------------------------ |
| 386 | |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 387 | /** |
| 388 | * Keeps existing flashdata available to next request. |
| 389 | * |
Johnathan Croom | 9d9849b | 2012-11-24 13:03:13 -0700 | [diff] [blame] | 390 | * @param mixed Item key(s) |
Darren Hill | 5073a37 | 2011-08-31 13:54:19 -0400 | [diff] [blame] | 391 | * @return void |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 392 | */ |
| 393 | public function keep_flashdata($key) |
| 394 | { |
Johnathan Croom | 8d8543d | 2012-11-25 10:36:57 -0700 | [diff] [blame] | 395 | |
| 396 | if (is_array($key)) |
Johnathan Croom | 4beca5c | 2012-11-23 18:32:46 -0700 | [diff] [blame] | 397 | { |
Johnathan Croom | 8d8543d | 2012-11-25 10:36:57 -0700 | [diff] [blame] | 398 | foreach ($key as $k) |
| 399 | { |
| 400 | $this->keep_flashdata($k); |
| 401 | } |
| 402 | |
| 403 | return; |
Johnathan Croom | 4beca5c | 2012-11-23 18:32:46 -0700 | [diff] [blame] | 404 | } |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 405 | |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 406 | // 'old' flashdata gets removed. Here we mark all flashdata as 'new' to preserve it from _flashdata_sweep() |
| 407 | // Note the function will return NULL if the $key provided cannot be found |
| 408 | $old_flashdata_key = self::FLASHDATA_KEY.self::FLASHDATA_OLD.$key; |
| 409 | $value = $this->userdata($old_flashdata_key); |
| 410 | |
Darren Hill | 5073a37 | 2011-08-31 13:54:19 -0400 | [diff] [blame] | 411 | $new_flashdata_key = self::FLASHDATA_KEY.self::FLASHDATA_NEW.$key; |
| 412 | $this->set_userdata($new_flashdata_key, $value); |
| 413 | } |
| 414 | |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 415 | // ------------------------------------------------------------------------ |
| 416 | |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 417 | /** |
| 418 | * Fetch a specific flashdata item from the session array |
| 419 | * |
| 420 | * @param string Item key |
| 421 | * @return string |
| 422 | */ |
| 423 | public function flashdata($key) |
| 424 | { |
| 425 | // Prepend key and retrieve value |
| 426 | $flashdata_key = self::FLASHDATA_KEY.self::FLASHDATA_OLD.$key; |
| 427 | return $this->userdata($flashdata_key); |
| 428 | } |
| 429 | |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 430 | // ------------------------------------------------------------------------ |
| 431 | |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 432 | /** |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 433 | * Add or change tempdata, only available until expiration |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 434 | * |
| 435 | * @param mixed Item name or array of items |
| 436 | * @param string Item value or empty string |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 437 | * @param int Item lifetime in seconds or 0 for default |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 438 | * @return void |
| 439 | */ |
| 440 | public function set_tempdata($newdata = array(), $newval = '', $expire = 0) |
| 441 | { |
| 442 | // Set expiration time |
| 443 | $expire = time() + ($expire ? $expire : self::TEMP_EXP_DEF); |
| 444 | |
| 445 | // Wrap item as array if singular |
| 446 | if (is_string($newdata)) |
| 447 | { |
| 448 | $newdata = array($newdata => $newval); |
| 449 | } |
| 450 | |
| 451 | // Get or create expiration list |
| 452 | $expirations = $this->userdata(self::EXPIRATION_KEY); |
dchill42 | 77ee3fd | 2012-07-24 11:50:01 -0400 | [diff] [blame] | 453 | if ( ! $expirations) |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 454 | { |
| 455 | $expirations = array(); |
| 456 | } |
| 457 | |
| 458 | // Prepend each key name and set value |
| 459 | if (count($newdata) > 0) |
| 460 | { |
| 461 | foreach ($newdata as $key => $val) |
| 462 | { |
| 463 | $tempdata_key = self::FLASHDATA_KEY.self::FLASHDATA_EXP.$key; |
| 464 | $expirations[$tempdata_key] = $expire; |
| 465 | $this->set_userdata($tempdata_key, $val); |
| 466 | } |
| 467 | } |
| 468 | |
| 469 | // Update expiration list |
| 470 | $this->set_userdata(self::EXPIRATION_KEY, $expirations); |
| 471 | } |
| 472 | |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 473 | // ------------------------------------------------------------------------ |
| 474 | |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 475 | /** |
| 476 | * Delete a temporary session variable from the "userdata" array |
| 477 | * |
Darren Hill | 5073a37 | 2011-08-31 13:54:19 -0400 | [diff] [blame] | 478 | * @param mixed Item name or array of item names |
| 479 | * @return void |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 480 | */ |
| 481 | public function unset_tempdata($newdata = array()) |
| 482 | { |
| 483 | // Get expirations list |
| 484 | $expirations = $this->userdata(self::EXPIRATION_KEY); |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 485 | if (empty($expirations)) |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 486 | { |
| 487 | // Nothing to do |
| 488 | return; |
| 489 | } |
| 490 | |
| 491 | // Wrap single name as array |
| 492 | if (is_string($newdata)) |
| 493 | { |
| 494 | $newdata = array($newdata => ''); |
| 495 | } |
| 496 | |
| 497 | // Prepend each item name and unset |
| 498 | if (count($newdata) > 0) |
| 499 | { |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 500 | foreach (array_keys($newdata) as $key) |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 501 | { |
| 502 | $tempdata_key = self::FLASHDATA_KEY.self::FLASHDATA_EXP.$key; |
| 503 | unset($expirations[$tempdata_key]); |
| 504 | $this->unset_userdata($tempdata_key); |
| 505 | } |
| 506 | } |
| 507 | |
| 508 | // Update expiration list |
| 509 | $this->set_userdata(self::EXPIRATION_KEY, $expirations); |
| 510 | } |
| 511 | |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 512 | // ------------------------------------------------------------------------ |
| 513 | |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 514 | /** |
| 515 | * Fetch a specific tempdata item from the session array |
| 516 | * |
Darren Hill | 5073a37 | 2011-08-31 13:54:19 -0400 | [diff] [blame] | 517 | * @param string Item key |
| 518 | * @return string |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 519 | */ |
| 520 | public function tempdata($key) |
| 521 | { |
| 522 | // Prepend key and return value |
| 523 | $tempdata_key = self::FLASHDATA_KEY.self::FLASHDATA_EXP.$key; |
| 524 | return $this->userdata($tempdata_key); |
| 525 | } |
| 526 | |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 527 | // ------------------------------------------------------------------------ |
| 528 | |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 529 | /** |
| 530 | * Identifies flashdata as 'old' for removal |
| 531 | * when _flashdata_sweep() runs. |
| 532 | * |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 533 | * @return void |
| 534 | */ |
Darren Hill | a2ae657 | 2011-09-01 07:36:26 -0400 | [diff] [blame] | 535 | protected function _flashdata_mark() |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 536 | { |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 537 | foreach ($this->all_userdata() as $name => $value) |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 538 | { |
| 539 | $parts = explode(self::FLASHDATA_NEW, $name); |
Andrey Andreev | e24eed7 | 2012-11-02 23:33:45 +0200 | [diff] [blame] | 540 | if (count($parts) === 2) |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 541 | { |
| 542 | $new_name = self::FLASHDATA_KEY.self::FLASHDATA_OLD.$parts[1]; |
| 543 | $this->set_userdata($new_name, $value); |
| 544 | $this->unset_userdata($name); |
| 545 | } |
| 546 | } |
| 547 | } |
| 548 | |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 549 | // ------------------------------------------------------------------------ |
| 550 | |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 551 | /** |
| 552 | * Removes all flashdata marked as 'old' |
| 553 | * |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 554 | * @return void |
| 555 | */ |
Darren Hill | a2ae657 | 2011-09-01 07:36:26 -0400 | [diff] [blame] | 556 | protected function _flashdata_sweep() |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 557 | { |
| 558 | $userdata = $this->all_userdata(); |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 559 | foreach (array_keys($userdata) as $key) |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 560 | { |
| 561 | if (strpos($key, self::FLASHDATA_OLD)) |
| 562 | { |
| 563 | $this->unset_userdata($key); |
| 564 | } |
| 565 | } |
| 566 | } |
| 567 | |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 568 | // ------------------------------------------------------------------------ |
| 569 | |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 570 | /** |
| 571 | * Removes all expired tempdata |
| 572 | * |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 573 | * @return void |
| 574 | */ |
Darren Hill | a2ae657 | 2011-09-01 07:36:26 -0400 | [diff] [blame] | 575 | protected function _tempdata_sweep() |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 576 | { |
| 577 | // Get expirations list |
| 578 | $expirations = $this->userdata(self::EXPIRATION_KEY); |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 579 | if (empty($expirations)) |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 580 | { |
| 581 | // Nothing to do |
| 582 | return; |
| 583 | } |
| 584 | |
| 585 | // Unset expired elements |
| 586 | $now = time(); |
| 587 | $userdata = $this->all_userdata(); |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 588 | foreach (array_keys($userdata) as $key) |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 589 | { |
| 590 | if (strpos($key, self::FLASHDATA_EXP) && $expirations[$key] < $now) |
| 591 | { |
| 592 | unset($expirations[$key]); |
| 593 | $this->unset_userdata($key); |
| 594 | } |
| 595 | } |
| 596 | |
| 597 | // Update expiration list |
| 598 | $this->set_userdata(self::EXPIRATION_KEY, $expirations); |
| 599 | } |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 600 | |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 601 | } |
| 602 | |
| 603 | // ------------------------------------------------------------------------ |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 604 | |
| 605 | /** |
Darren Hill | 5073a37 | 2011-08-31 13:54:19 -0400 | [diff] [blame] | 606 | * CI_Session_driver Class |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 607 | * |
Darren Hill | 5073a37 | 2011-08-31 13:54:19 -0400 | [diff] [blame] | 608 | * Extend this class to make a new CI_Session driver. |
| 609 | * A CI_Session driver basically manages an array of name/value pairs with some sort of storage mechanism. |
| 610 | * To make a new driver, derive from (extend) CI_Session_driver. Overload the initialize method and read or create |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 611 | * session data. Then implement a save handler to write changed data to storage (sess_save), a destroy handler |
| 612 | * to remove deleted data (sess_destroy), and an access handler to expose the data (get_userdata). |
Darren Hill | 5073a37 | 2011-08-31 13:54:19 -0400 | [diff] [blame] | 613 | * Put your driver in the libraries/Session/drivers folder anywhere in the loader paths. This includes the |
| 614 | * application directory, the system directory, or any path you add with $CI->load->add_package_path(). |
| 615 | * Your driver must be named CI_Session_<name>, and your filename must be Session_<name>.php, |
| 616 | * preferably also capitalized. (e.g.: CI_Session_foo in libraries/Session/drivers/Session_foo.php) |
| 617 | * Then specify the driver by setting 'sess_driver' in your config file or as a parameter when loading the CI_Session |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 618 | * object. (e.g.: $config['sess_driver'] = 'foo'; OR $CI->load->driver('session', array('sess_driver' => 'foo')); ) |
| 619 | * Already provided are the Native driver, which manages the native PHP $_SESSION array, and |
| 620 | * the Cookie driver, which manages the data in a browser cookie, with optional extra storage in a database table. |
| 621 | * |
Darren Hill | 5073a37 | 2011-08-31 13:54:19 -0400 | [diff] [blame] | 622 | * @package CodeIgniter |
| 623 | * @subpackage Libraries |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 624 | * @category Sessions |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 625 | * @author EllisLab Dev Team |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 626 | */ |
Darren Hill | 5073a37 | 2011-08-31 13:54:19 -0400 | [diff] [blame] | 627 | abstract class CI_Session_driver extends CI_Driver { |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 628 | |
Andrey Andreev | 0fa95bd | 2012-11-01 23:33:14 +0200 | [diff] [blame] | 629 | /** |
| 630 | * CI Singleton |
| 631 | * |
| 632 | * @see get_instance() |
| 633 | * @var object |
| 634 | */ |
Andrey Andreev | 2e3e230 | 2012-10-09 15:52:34 +0300 | [diff] [blame] | 635 | protected $CI; |
| 636 | |
Andrey Andreev | 0fa95bd | 2012-11-01 23:33:14 +0200 | [diff] [blame] | 637 | // ------------------------------------------------------------------------ |
| 638 | |
Andrey Andreev | 2e3e230 | 2012-10-09 15:52:34 +0300 | [diff] [blame] | 639 | /** |
| 640 | * Constructor |
| 641 | * |
| 642 | * Gets the CI singleton, so that individual drivers |
| 643 | * don't have to do it separately. |
| 644 | * |
| 645 | * @return void |
| 646 | */ |
| 647 | public function __construct() |
| 648 | { |
| 649 | $this->CI =& get_instance(); |
| 650 | } |
| 651 | |
| 652 | // ------------------------------------------------------------------------ |
| 653 | |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 654 | /** |
| 655 | * Decorate |
| 656 | * |
| 657 | * Decorates the child with the parent driver lib's methods and properties |
| 658 | * |
| 659 | * @param object Parent library object |
| 660 | * @return void |
| 661 | */ |
| 662 | public function decorate($parent) |
| 663 | { |
| 664 | // Call base class decorate first |
| 665 | parent::decorate($parent); |
| 666 | |
dchill42 | c587225 | 2012-07-30 14:53:11 -0400 | [diff] [blame] | 667 | // Call initialize method now that driver has access to $this->_parent |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 668 | $this->initialize(); |
| 669 | } |
| 670 | |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 671 | // ------------------------------------------------------------------------ |
| 672 | |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 673 | /** |
| 674 | * __call magic method |
| 675 | * |
| 676 | * Handles access to the parent driver library's methods |
| 677 | * |
Darren Hill | 5073a37 | 2011-08-31 13:54:19 -0400 | [diff] [blame] | 678 | * @param string Library method name |
| 679 | * @param array Method arguments (default: none) |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 680 | * @return mixed |
| 681 | */ |
| 682 | public function __call($method, $args = array()) |
| 683 | { |
| 684 | // Make sure the parent library uses this driver |
dchill42 | c587225 | 2012-07-30 14:53:11 -0400 | [diff] [blame] | 685 | $this->_parent->select_driver(get_class($this)); |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 686 | return parent::__call($method, $args); |
| 687 | } |
| 688 | |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 689 | // ------------------------------------------------------------------------ |
| 690 | |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 691 | /** |
| 692 | * Initialize driver |
| 693 | * |
Darren Hill | 5073a37 | 2011-08-31 13:54:19 -0400 | [diff] [blame] | 694 | * @return void |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 695 | */ |
| 696 | protected function initialize() |
| 697 | { |
| 698 | // Overload this method to implement initialization |
| 699 | } |
| 700 | |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 701 | // ------------------------------------------------------------------------ |
| 702 | |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 703 | /** |
| 704 | * Save the session data |
| 705 | * |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 706 | * Data in the array has changed - perform any storage synchronization |
| 707 | * necessary. The child class MUST implement this abstract method! |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 708 | * |
Darren Hill | 5073a37 | 2011-08-31 13:54:19 -0400 | [diff] [blame] | 709 | * @return void |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 710 | */ |
| 711 | abstract public function sess_save(); |
| 712 | |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 713 | // ------------------------------------------------------------------------ |
| 714 | |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 715 | /** |
| 716 | * Destroy the current session |
| 717 | * |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 718 | * Clean up storage for this session - it has been terminated. |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 719 | * The child class MUST implement this abstract method! |
| 720 | * |
Darren Hill | 5073a37 | 2011-08-31 13:54:19 -0400 | [diff] [blame] | 721 | * @return void |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 722 | */ |
| 723 | abstract public function sess_destroy(); |
| 724 | |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 725 | // ------------------------------------------------------------------------ |
| 726 | |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 727 | /** |
| 728 | * Regenerate the current session |
| 729 | * |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 730 | * Regenerate the session ID. |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 731 | * The child class MUST implement this abstract method! |
| 732 | * |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 733 | * @param bool Destroy session data flag (default: false) |
Darren Hill | 5073a37 | 2011-08-31 13:54:19 -0400 | [diff] [blame] | 734 | * @return void |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 735 | */ |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 736 | abstract public function sess_regenerate($destroy = FALSE); |
| 737 | |
| 738 | // ------------------------------------------------------------------------ |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 739 | |
| 740 | /** |
| 741 | * Get a reference to user data array |
| 742 | * |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 743 | * Give array access to the main CI_Session object. |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 744 | * The child class MUST implement this abstract method! |
| 745 | * |
Darren Hill | 5073a37 | 2011-08-31 13:54:19 -0400 | [diff] [blame] | 746 | * @return array Reference to userdata |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 747 | */ |
| 748 | abstract public function &get_userdata(); |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 749 | |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 750 | } |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 751 | |
| 752 | /* End of file Session.php */ |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 753 | /* Location: ./system/libraries/Session/Session.php */ |