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 |
darwinel | 871754a | 2014-02-11 17:34:57 +0100 | [diff] [blame] | 21 | * @copyright Copyright (c) 2008 - 2014, 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 | * |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 32 | * @package CodeIgniter |
| 33 | * @subpackage Libraries |
| 34 | * @category Sessions |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 35 | * @author Andrey Andreev |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 36 | * @link http://codeigniter.com/user_guide/libraries/sessions.html |
| 37 | */ |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 38 | class CI_Session { |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 39 | |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 40 | protected $_driver = 'files'; |
Andrey Andreev | dfb39be | 2014-10-06 01:50:14 +0300 | [diff] [blame] | 41 | protected $_config; |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 42 | |
Andrey Andreev | 0fa95bd | 2012-11-01 23:33:14 +0200 | [diff] [blame] | 43 | // ------------------------------------------------------------------------ |
| 44 | |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 45 | /** |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 46 | * Class constructor |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 47 | * |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 48 | * @param array $params Configuration parameters |
Andrey Andreev | 2e3e230 | 2012-10-09 15:52:34 +0300 | [diff] [blame] | 49 | * @return void |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 50 | */ |
| 51 | public function __construct(array $params = array()) |
| 52 | { |
Andrey Andreev | 2e3e230 | 2012-10-09 15:52:34 +0300 | [diff] [blame] | 53 | // No sessions under CLI |
Andrey Andreev | f964b16 | 2013-11-12 17:04:55 +0200 | [diff] [blame] | 54 | if (is_cli()) |
Andrey Andreev | 2e3e230 | 2012-10-09 15:52:34 +0300 | [diff] [blame] | 55 | { |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 56 | log_message('debug', 'Session: Initialization under CLI aborted.'); |
| 57 | return; |
| 58 | } |
| 59 | elseif ((bool) ini_get('session.auto_start')) |
| 60 | { |
| 61 | log_message('error', 'Session: session.auto_start is enabled in php.ini. Aborting.'); |
| 62 | return; |
| 63 | } |
| 64 | elseif ( ! empty($params['driver'])) |
| 65 | { |
| 66 | $this->_driver = $params['driver']; |
| 67 | unset($params['driver']); |
| 68 | } |
Andrey Andreev | dfb39be | 2014-10-06 01:50:14 +0300 | [diff] [blame] | 69 | elseif ($driver = config_item('sess_driver')) |
Andrey Andreev | 34b1ef5 | 2014-05-31 21:23:41 +0300 | [diff] [blame] | 70 | { |
| 71 | $this->_driver = $driver; |
| 72 | } |
Andrey Andreev | ac4f472 | 2014-06-02 11:16:32 +0300 | [diff] [blame] | 73 | // Note: BC workaround |
| 74 | elseif (config_item('sess_use_database')) |
| 75 | { |
| 76 | $this->_driver = 'database'; |
| 77 | } |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 78 | |
| 79 | if (($class = $this->_ci_load_classes($this->_driver)) === FALSE) |
| 80 | { |
Andrey Andreev | 2e3e230 | 2012-10-09 15:52:34 +0300 | [diff] [blame] | 81 | return; |
| 82 | } |
| 83 | |
Andrey Andreev | dfb39be | 2014-10-06 01:50:14 +0300 | [diff] [blame] | 84 | // Configuration ... |
| 85 | $this->_configure($params); |
| 86 | |
| 87 | $class = new $class($this->_config); |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 88 | if ($class instanceof SessionHandlerInterface) |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 89 | { |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 90 | if (is_php('5.4')) |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 91 | { |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 92 | session_set_save_handler($class, TRUE); |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 93 | } |
| 94 | else |
| 95 | { |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 96 | session_set_save_handler( |
| 97 | array($class, 'open'), |
| 98 | array($class, 'close'), |
| 99 | array($class, 'read'), |
| 100 | array($class, 'write'), |
| 101 | array($class, 'destroy'), |
| 102 | array($class, 'gc') |
| 103 | ); |
| 104 | |
| 105 | register_shutdown_function('session_write_close'); |
| 106 | } |
| 107 | } |
| 108 | else |
| 109 | { |
| 110 | log_message('error', "Session: Driver '".$this->_driver."' doesn't implement SessionHandlerInterface. Aborting."); |
| 111 | return; |
| 112 | } |
| 113 | |
Andrey Andreev | dfb39be | 2014-10-06 01:50:14 +0300 | [diff] [blame] | 114 | // Work-around for PHP bug #66827 (https://bugs.php.net/bug.php?id=66827) |
| 115 | // |
| 116 | // The session ID sanitizer doesn't check for the value type and blindly does |
| 117 | // an implicit cast to string, which triggers an 'Array to string' E_NOTICE. |
| 118 | if (isset($_COOKIE[$this->_cookie_name]) && ! is_string($_COOKIE[$this->_cookie_name])) |
| 119 | { |
| 120 | unset($_COOKIE[$this->_cookie_name]); |
| 121 | } |
| 122 | |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 123 | session_start(); |
Andrey Andreev | dfb39be | 2014-10-06 01:50:14 +0300 | [diff] [blame] | 124 | |
Andrey Andreev | 8e60b9a | 2014-11-04 11:08:06 +0200 | [diff] [blame^] | 125 | if (($regenerate_time = config_item('sess_time_to_update')) > 0) |
| 126 | { |
| 127 | if ( ! isset($_SESSION['__ci_last_regenerate'])) |
| 128 | { |
| 129 | $_SESSION['__ci_last_regenerate'] = time(); |
| 130 | } |
| 131 | elseif ($_SESSION['__ci_last_regenerate'] < (time() - $regenerate_time)) |
| 132 | { |
| 133 | $this->sess_regenerate(FALSE); |
| 134 | } |
| 135 | } |
Andrey Andreev | dfb39be | 2014-10-06 01:50:14 +0300 | [diff] [blame] | 136 | // Another work-around ... PHP doesn't seem to send the session cookie |
| 137 | // unless it is being currently created or regenerated |
Andrey Andreev | 8e60b9a | 2014-11-04 11:08:06 +0200 | [diff] [blame^] | 138 | elseif (isset($_COOKIE[$this->_config['cookie_name']]) && $_COOKIE[$this->_config['cookie_name']] === session_id()) |
Andrey Andreev | dfb39be | 2014-10-06 01:50:14 +0300 | [diff] [blame] | 139 | { |
| 140 | setcookie( |
| 141 | $this->_config['cookie_name'], |
| 142 | session_id(), |
| 143 | (empty($this->_config['cookie_lifetime']) ? 0 : time() + $this->_config['cookie_lifetime']), |
| 144 | $this->_config['cookie_path'], |
| 145 | $this->_config['cookie_domain'], |
| 146 | $this->_config['cookie_secure'], |
| 147 | TRUE |
| 148 | ); |
| 149 | } |
| 150 | |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 151 | $this->_ci_init_vars(); |
Andrey Andreev | dfb39be | 2014-10-06 01:50:14 +0300 | [diff] [blame] | 152 | /* |
| 153 | Need to test if this is necessary for a custom driver or if it's only |
| 154 | relevant to PHP's own files handler. |
| 155 | |
| 156 | https://bugs.php.net/bug.php?id=65475 |
| 157 | do this after session is started: |
| 158 | if (is_php('5.5.2') && ! is_php('5.5.4')) |
| 159 | { |
| 160 | $session_id = session_id(); |
| 161 | if ($_COOKIE[$this->_cookie_name] !== $session_id && file_exists(teh file)) |
| 162 | { |
| 163 | unlink(<teh file>); |
| 164 | } |
| 165 | } |
| 166 | */ |
| 167 | |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 168 | log_message('debug', "Session: Class initialized using '".$this->_driver."' driver."); |
| 169 | } |
| 170 | |
| 171 | // ------------------------------------------------------------------------ |
| 172 | |
| 173 | protected function _ci_load_classes($driver) |
| 174 | { |
| 175 | // PHP 5.4 compatibility |
| 176 | interface_exists('SessionHandlerInterface', FALSE) OR require_once(BASEPATH.'libraries/Session/SessionHandlerInterface.php'); |
| 177 | |
| 178 | $prefix = config_item('subclass_prefix'); |
| 179 | |
| 180 | if ( ! class_exists('CI_Session_driver', FALSE)) |
| 181 | { |
Andrey Andreev | e86603f | 2014-06-11 14:03:36 +0300 | [diff] [blame] | 182 | require_once( |
| 183 | file_exists(APPPATH.'libraries/Session/Session_driver.php') |
| 184 | ? APPPATH.'libraries/Session/Session_driver.php' |
| 185 | : BASEPATH.'libraries/Session/Session_driver.php' |
| 186 | ); |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 187 | |
| 188 | if (file_exists($file_path = APPPATH.'libraries/Session/'.$prefix.'Session_driver.php')) |
| 189 | { |
| 190 | require_once($file_path); |
| 191 | } |
| 192 | } |
| 193 | |
| 194 | $class = 'Session_'.$driver.'_driver'; |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 195 | if ( ! class_exists('CI_'.$class, FALSE)) |
| 196 | { |
| 197 | if (file_exists($file_path = APPPATH.'libraries/Session/drivers/'.$class.'.php') OR file_exists($file_path = BASEPATH.'libraries/Session/drivers/'.$class.'.php')) |
| 198 | { |
| 199 | require_once($file_path); |
| 200 | } |
| 201 | |
| 202 | if ( ! class_exists('CI_'.$class, FALSE)) |
| 203 | { |
| 204 | log_message('error', "Session: Configured driver '".$driver."' was not found. Aborting."); |
| 205 | return FALSE; |
| 206 | } |
| 207 | } |
| 208 | |
| 209 | if ( ! class_exists($prefix.$class) && file_exists($file_path = APPPATH.'libraries/Session/drivers/'.$prefix.$class.'.php')) |
| 210 | { |
| 211 | require_once($file_path); |
| 212 | if (class_exists($prefix.$class, FALSE)) |
| 213 | { |
| 214 | return $prefix.$class; |
| 215 | } |
| 216 | else |
| 217 | { |
| 218 | log_message('debug', 'Session: '.$prefix.$class.".php found but it doesn't declare class ".$prefix.$class.'.'); |
| 219 | } |
| 220 | } |
| 221 | |
| 222 | return 'CI_'.$class; |
| 223 | } |
| 224 | |
| 225 | // ------------------------------------------------------------------------ |
| 226 | |
| 227 | /** |
Andrey Andreev | dfb39be | 2014-10-06 01:50:14 +0300 | [diff] [blame] | 228 | * Configuration |
| 229 | * |
| 230 | * Handle input parameters and configuration defaults |
| 231 | * |
| 232 | * @param array &$params Input parameters |
| 233 | * @return void |
| 234 | */ |
| 235 | protected function _configure(&$params) |
| 236 | { |
| 237 | $expiration = config_item('sess_expiration'); |
| 238 | |
| 239 | if (isset($params['cookie_lifetime'])) |
| 240 | { |
| 241 | $params['cookie_lifetime'] = (int) $params['cookie_lifetime']; |
| 242 | } |
| 243 | else |
| 244 | { |
| 245 | $params['cookie_lifetime'] = ( ! isset($expiration) && config_item('sess_expire_on_close')) |
| 246 | ? 0 : (int) $expiration; |
| 247 | } |
| 248 | |
| 249 | isset($params['cookie_name']) OR $params['cookie_name'] = config_item('sess_cookie_name'); |
| 250 | if (empty($params['cookie_name'])) |
| 251 | { |
| 252 | $params['cookie_name'] = ini_get('session.name'); |
| 253 | } |
| 254 | else |
| 255 | { |
| 256 | ini_set('session.name', $params['cookie_name']); |
| 257 | } |
| 258 | |
| 259 | isset($params['cookie_path']) OR $params['cookie_path'] = config_item('cookie_path'); |
Andrey Andreev | 41b546d | 2014-10-06 03:01:22 +0300 | [diff] [blame] | 260 | isset($params['cookie_domain']) OR $params['cookie_domain'] = config_item('cookie_domain'); |
Andrey Andreev | dfb39be | 2014-10-06 01:50:14 +0300 | [diff] [blame] | 261 | isset($params['cookie_secure']) OR $params['cookie_secure'] = (bool) config_item('cookie_secure'); |
| 262 | |
| 263 | session_set_cookie_params( |
| 264 | $params['cookie_lifetime'], |
| 265 | $params['cookie_path'], |
| 266 | $params['cookie_domain'], |
| 267 | $params['cookie_secure'], |
| 268 | TRUE // HttpOnly; Yes, this is intentional and not configurable for security reasons |
| 269 | ); |
| 270 | |
| 271 | if (empty($expiration)) |
| 272 | { |
| 273 | $params['expiration'] = (int) ini_get('session.gc_maxlifetime'); |
| 274 | } |
| 275 | else |
| 276 | { |
| 277 | $params['expiration'] = (int) $expiration; |
| 278 | ini_set('session.gc_maxlifetime', $expiration); |
| 279 | } |
| 280 | |
| 281 | $params['match_ip'] = (bool) (isset($params['match_ip']) ? $params['match_ip'] : config_item('sess_match_ip')); |
| 282 | |
| 283 | isset($params['save_path']) OR $params['save_path'] = config_item('sess_save_path'); |
| 284 | |
| 285 | $this->_config = $params; |
| 286 | |
| 287 | // Security is king |
| 288 | ini_set('session.use_trans_id', 0); |
| 289 | ini_set('session.use_strict_mode', 1); |
| 290 | ini_set('session.use_cookies', 1); |
| 291 | ini_set('session.use_only_cookies', 1); |
| 292 | ini_set('session.hash_function', 1); |
| 293 | ini_set('session.hash_bits_per_character', 4); |
| 294 | } |
| 295 | |
| 296 | // ------------------------------------------------------------------------ |
| 297 | |
| 298 | /** |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 299 | * Handle temporary variables |
| 300 | * |
| 301 | * Clears old "flash" data, marks the new one for deletion and handles |
| 302 | * "temp" data deletion. |
| 303 | * |
| 304 | * @return void |
| 305 | */ |
| 306 | protected function _ci_init_vars() |
| 307 | { |
| 308 | if ( ! empty($_SESSION['__ci_vars'])) |
| 309 | { |
| 310 | $current_time = time(); |
| 311 | |
| 312 | foreach ($_SESSION['__ci_vars'] as $key => &$value) |
| 313 | { |
| 314 | if ($value === 'new') |
| 315 | { |
| 316 | $_SESSION['__ci_vars'][$key] = 'old'; |
| 317 | } |
| 318 | // Hacky, but 'old' will (implicitly) always be less than time() ;) |
| 319 | // DO NOT move this above the 'new' check! |
| 320 | elseif ($value < $current_time) |
| 321 | { |
| 322 | unset($_SESSION[$key], $_SESSION['__ci_vars'][$key]); |
| 323 | } |
| 324 | } |
| 325 | |
| 326 | if (empty($_SESSION['__ci_vars'])) |
| 327 | { |
| 328 | unset($_SESSION['__ci_vars']); |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 329 | } |
| 330 | } |
| 331 | } |
| 332 | |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 333 | // ------------------------------------------------------------------------ |
| 334 | |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 335 | /** |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 336 | * Mark as flash |
| 337 | * |
| 338 | * @param mixed $key Session data key(s) |
| 339 | * @return bool |
| 340 | */ |
| 341 | public function mark_as_flash($key) |
| 342 | { |
| 343 | if (is_array($key)) |
| 344 | { |
| 345 | for ($i = 0, $c = count($key); $i < $c; $i++) |
| 346 | { |
| 347 | if ( ! isset($_SESSION[$key[$i]])) |
| 348 | { |
| 349 | return FALSE; |
| 350 | } |
| 351 | } |
| 352 | |
| 353 | $new = array_fill_keys($key, 'new'); |
| 354 | |
| 355 | $_SESSION['__ci_vars'] = isset($_SESSION['__ci_vars']) |
| 356 | ? array_merge($_SESSION['__ci_vars'], $new) |
| 357 | : $new; |
| 358 | |
| 359 | return TRUE; |
| 360 | } |
| 361 | |
| 362 | if ( ! isset($_SESSION[$key])) |
| 363 | { |
| 364 | return FALSE; |
| 365 | } |
| 366 | |
| 367 | $_SESSION['__ci_vars'][$key] = 'new'; |
| 368 | return TRUE; |
| 369 | } |
| 370 | |
| 371 | // ------------------------------------------------------------------------ |
| 372 | |
| 373 | /** |
| 374 | * Get flash keys |
| 375 | * |
| 376 | * @return array |
| 377 | */ |
| 378 | public function get_flash_keys() |
| 379 | { |
| 380 | if ( ! isset($_SESSION['__ci_vars'])) |
| 381 | { |
| 382 | return array(); |
| 383 | } |
| 384 | |
| 385 | $keys = array(); |
| 386 | foreach (array_keys($_SESSION['__ci_vars']) as $key) |
| 387 | { |
| 388 | is_int($_SESSION['__ci_vars'][$key]) OR $keys[] = $key; |
| 389 | } |
| 390 | |
| 391 | return $keys; |
| 392 | } |
| 393 | |
| 394 | // ------------------------------------------------------------------------ |
| 395 | |
| 396 | /** |
| 397 | * Unmark flash |
| 398 | * |
| 399 | * @param mixed $key Session data key(s) |
| 400 | * @return void |
| 401 | */ |
| 402 | public function unmark_flash($key) |
| 403 | { |
| 404 | if (empty($_SESSION['__ci_vars'])) |
| 405 | { |
| 406 | return; |
| 407 | } |
| 408 | |
| 409 | is_array($key) OR $key = array($key); |
| 410 | |
| 411 | foreach ($key as $k) |
| 412 | { |
| 413 | if (isset($_SESSION['__ci_vars'][$k]) && ! is_int($_SESSION['__ci_vars'][$k])) |
| 414 | { |
| 415 | unset($_SESSION['__ci_vars'][$k]); |
| 416 | } |
| 417 | } |
| 418 | |
| 419 | if (empty($_SESSION['__ci_vars'])) |
| 420 | { |
| 421 | unset($_SESSION['__ci_vars']); |
| 422 | } |
| 423 | } |
| 424 | |
| 425 | // ------------------------------------------------------------------------ |
| 426 | |
| 427 | /** |
| 428 | * Mark as temp |
| 429 | * |
| 430 | * @param mixed $key Session data key(s) |
| 431 | * @param int $ttl Time-to-live in seconds |
| 432 | * @return bool |
| 433 | */ |
| 434 | public function mark_as_temp($key, $ttl = 300) |
| 435 | { |
| 436 | $ttl += time(); |
| 437 | |
| 438 | if (is_array($key)) |
| 439 | { |
| 440 | $temp = array(); |
| 441 | |
| 442 | foreach ($key as $k => $v) |
| 443 | { |
| 444 | // Do we have a key => ttl pair, or just a key? |
| 445 | if (is_int($k)) |
| 446 | { |
| 447 | $k = $v; |
| 448 | $v = $ttl; |
| 449 | } |
| 450 | else |
| 451 | { |
| 452 | $v += time(); |
| 453 | } |
| 454 | |
| 455 | if ( ! isset($_SESSION[$k])) |
| 456 | { |
| 457 | return FALSE; |
| 458 | } |
| 459 | |
| 460 | $temp[$k] = $ts; |
| 461 | } |
| 462 | |
| 463 | $_SESSION['__ci_vars'] = isset($_SESSION['__ci_vars']) |
| 464 | ? array_merge($_SESSION['__ci_vars'], $temp) |
| 465 | : $temp; |
| 466 | |
| 467 | return TRUE; |
| 468 | } |
| 469 | |
| 470 | if ( ! isset($_SESSION[$key])) |
| 471 | { |
| 472 | return FALSE; |
| 473 | } |
| 474 | |
| 475 | $_SESSION['__ci_vars'][$key] = $ttl; |
| 476 | return TRUE; |
| 477 | } |
| 478 | |
| 479 | // ------------------------------------------------------------------------ |
| 480 | |
| 481 | /** |
| 482 | * Get temp keys |
| 483 | * |
| 484 | * @return array |
| 485 | */ |
| 486 | public function get_temp_keys() |
| 487 | { |
| 488 | if ( ! isset($_SESSION['__ci_vars'])) |
| 489 | { |
| 490 | return array(); |
| 491 | } |
| 492 | |
| 493 | $keys = array(); |
| 494 | foreach (array_keys($_SESSION['__ci_vars']) as $key) |
| 495 | { |
| 496 | is_int($_SESSION['__ci_vars'][$key]) && $keys[] = $key; |
| 497 | } |
| 498 | |
| 499 | return $keys; |
| 500 | } |
| 501 | |
| 502 | // ------------------------------------------------------------------------ |
| 503 | |
| 504 | /** |
| 505 | * Unmark flash |
| 506 | * |
| 507 | * @param mixed $key Session data key(s) |
| 508 | * @return void |
| 509 | */ |
| 510 | public function unmark_temp($key) |
| 511 | { |
| 512 | if (empty($_SESSION['__ci_vars'])) |
| 513 | { |
| 514 | return; |
| 515 | } |
| 516 | |
| 517 | is_array($key) OR $key = array($key); |
| 518 | |
| 519 | foreach ($key as $k) |
| 520 | { |
| 521 | if (isset($_SESSION['__ci_vars'][$k]) && is_int($_SESSION['__ci_vars'][$k])) |
| 522 | { |
| 523 | unset($_SESSION['__ci_vars'][$k]); |
| 524 | } |
| 525 | } |
| 526 | |
| 527 | if (empty($_SESSION['__ci_vars'])) |
| 528 | { |
| 529 | unset($_SESSION['__ci_vars']); |
| 530 | } |
| 531 | } |
| 532 | |
| 533 | // ------------------------------------------------------------------------ |
| 534 | |
| 535 | /** |
| 536 | * __get() |
| 537 | * |
| 538 | * @param string $key 'session_id' or a session data key |
| 539 | * @return mixed |
| 540 | */ |
| 541 | public function __get($key) |
| 542 | { |
| 543 | // Note: Keep this order the same, just in case somebody wants to |
| 544 | // use 'session_id' as a session data key, for whatever reason |
| 545 | if (isset($_SESSION[$key])) |
| 546 | { |
| 547 | return $_SESSION[$key]; |
| 548 | } |
| 549 | elseif ($key === 'session_id') |
| 550 | { |
| 551 | return session_id(); |
| 552 | } |
| 553 | |
| 554 | return NULL; |
| 555 | } |
| 556 | |
| 557 | // ------------------------------------------------------------------------ |
| 558 | |
| 559 | /** |
| 560 | * __set() |
| 561 | * |
| 562 | * @param string $key Session data key |
| 563 | * @param mixed $value Session data value |
| 564 | * @return void |
| 565 | */ |
| 566 | public function __set($key, $value) |
| 567 | { |
| 568 | $_SESSION[$key] = $value; |
| 569 | } |
| 570 | |
| 571 | // ------------------------------------------------------------------------ |
| 572 | |
| 573 | /** |
| 574 | * Session destroy |
| 575 | * |
| 576 | * Legacy CI_Session compatibility method |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 577 | * |
Darren Hill | 5073a37 | 2011-08-31 13:54:19 -0400 | [diff] [blame] | 578 | * @return void |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 579 | */ |
| 580 | public function sess_destroy() |
| 581 | { |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 582 | session_destroy(); |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 583 | } |
| 584 | |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 585 | // ------------------------------------------------------------------------ |
| 586 | |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 587 | /** |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 588 | * Session regenerate |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 589 | * |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 590 | * Legacy CI_Session compatibility method |
| 591 | * |
| 592 | * @param bool $destroy Destroy old session data flag |
Darren Hill | 5073a37 | 2011-08-31 13:54:19 -0400 | [diff] [blame] | 593 | * @return void |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 594 | */ |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 595 | public function sess_regenerate($destroy = FALSE) |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 596 | { |
Andrey Andreev | 8e60b9a | 2014-11-04 11:08:06 +0200 | [diff] [blame^] | 597 | $_SESSION['__ci_last_regenerate'] = time(); |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 598 | session_regenerate_id($destroy); |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 599 | } |
| 600 | |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 601 | // ------------------------------------------------------------------------ |
| 602 | |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 603 | /** |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 604 | * Get userdata reference |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 605 | * |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 606 | * Legacy CI_Session compatibility method |
| 607 | * |
| 608 | * @returns array |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 609 | */ |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 610 | public function &get_userdata() |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 611 | { |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 612 | return $_SESSION; |
| 613 | } |
| 614 | |
| 615 | // ------------------------------------------------------------------------ |
| 616 | |
| 617 | /** |
| 618 | * Userdata (fetch) |
| 619 | * |
| 620 | * Legacy CI_Session compatibility method |
| 621 | * |
| 622 | * @param string $key Session data key |
| 623 | * @return mixed Session data value or NULL if not found |
| 624 | */ |
| 625 | public function userdata($key = NULL) |
| 626 | { |
| 627 | if (isset($key)) |
Andrey Andreev | ecc260e | 2014-01-24 14:20:13 +0200 | [diff] [blame] | 628 | { |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 629 | return isset($_SESSION[$key]) ? $_SESSION[$key] : NULL; |
| 630 | } |
| 631 | elseif (empty($_SESSION)) |
| 632 | { |
| 633 | return array(); |
Andrey Andreev | ecc260e | 2014-01-24 14:20:13 +0200 | [diff] [blame] | 634 | } |
| 635 | |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 636 | $userdata = array(); |
| 637 | $_exclude = array_merge( |
Andrey Andreev | ef41786 | 2014-06-04 21:28:13 +0300 | [diff] [blame] | 638 | array('__ci_vars'), |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 639 | $this->get_flash_keys(), |
| 640 | $this->get_temp_keys() |
| 641 | ); |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 642 | |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 643 | foreach (array_keys($_SESSION) as $key) |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 644 | { |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 645 | if ( ! in_array($key, $_exclude, TRUE)) |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 646 | { |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 647 | $userdata[$key] = $_SESSION[$key]; |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 648 | } |
| 649 | } |
| 650 | |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 651 | return $userdata; |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 652 | } |
| 653 | |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 654 | // ------------------------------------------------------------------------ |
| 655 | |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 656 | /** |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 657 | * Set userdata |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 658 | * |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 659 | * Legacy CI_Session compatibility method |
| 660 | * |
| 661 | * @param mixed $data Session data key or an associative array |
| 662 | * @param mixed $value Value to store |
Darren Hill | 5073a37 | 2011-08-31 13:54:19 -0400 | [diff] [blame] | 663 | * @return void |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 664 | */ |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 665 | public function set_userdata($data, $value = NULL) |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 666 | { |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 667 | if (is_array($data)) |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 668 | { |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 669 | foreach ($data as $key => &$value) |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 670 | { |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 671 | $_SESSION[$key] = $value; |
Johnathan Croom | 8d8543d | 2012-11-25 10:36:57 -0700 | [diff] [blame] | 672 | } |
| 673 | |
| 674 | return; |
Johnathan Croom | 4beca5c | 2012-11-23 18:32:46 -0700 | [diff] [blame] | 675 | } |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 676 | |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 677 | $_SESSION[$data] = $value; |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 678 | } |
| 679 | |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 680 | // ------------------------------------------------------------------------ |
| 681 | |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 682 | /** |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 683 | * Unset userdata |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 684 | * |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 685 | * Legacy CI_Session compatibility method |
| 686 | * |
| 687 | * @param mixed $data Session data key(s) |
| 688 | * @return void |
| 689 | */ |
| 690 | public function unset_userdata($key) |
| 691 | { |
| 692 | if (is_array($key)) |
| 693 | { |
| 694 | foreach ($key as $k) |
| 695 | { |
Andrey Andreev | d069b9b | 2014-09-16 10:18:16 +0300 | [diff] [blame] | 696 | unset($_SESSION[$k]); |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 697 | } |
| 698 | |
| 699 | return; |
| 700 | } |
| 701 | |
| 702 | unset($_SESSION[$key]); |
| 703 | } |
| 704 | |
| 705 | // ------------------------------------------------------------------------ |
| 706 | |
| 707 | /** |
| 708 | * All userdata (fetch) |
| 709 | * |
| 710 | * Legacy CI_Session compatibility method |
| 711 | * |
| 712 | * @return array $_SESSION, excluding flash data items |
| 713 | */ |
| 714 | public function all_userdata() |
| 715 | { |
| 716 | return $this->userdata(); |
| 717 | } |
| 718 | |
| 719 | // ------------------------------------------------------------------------ |
| 720 | |
| 721 | /** |
| 722 | * Has userdata |
| 723 | * |
| 724 | * Legacy CI_Session compatibility method |
| 725 | * |
| 726 | * @param string $key Session data key |
| 727 | * @return bool |
| 728 | */ |
| 729 | public function has_userdata($key) |
| 730 | { |
| 731 | return isset($_SESSION[$key]); |
| 732 | } |
| 733 | |
| 734 | // ------------------------------------------------------------------------ |
| 735 | |
| 736 | /** |
| 737 | * Flashdata (fetch) |
| 738 | * |
| 739 | * Legacy CI_Session compatibility method |
| 740 | * |
| 741 | * @param string $key Session data key |
| 742 | * @return mixed Session data value or NULL if not found |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 743 | */ |
Andrey Andreev | ecc260e | 2014-01-24 14:20:13 +0200 | [diff] [blame] | 744 | public function flashdata($key = NULL) |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 745 | { |
Andrey Andreev | ecc260e | 2014-01-24 14:20:13 +0200 | [diff] [blame] | 746 | if (isset($key)) |
| 747 | { |
Andrey Andreev | ef41786 | 2014-06-04 21:28:13 +0300 | [diff] [blame] | 748 | return (isset($_SESSION['__ci_vars'], $_SESSION['__ci_vars'][$key], $_SESSION[$key]) && ! is_int($_SESSION['__ci_vars'][$key])) |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 749 | ? $_SESSION[$key] |
| 750 | : NULL; |
Andrey Andreev | ecc260e | 2014-01-24 14:20:13 +0200 | [diff] [blame] | 751 | } |
| 752 | |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 753 | $flashdata = array(); |
| 754 | |
Andrey Andreev | ef41786 | 2014-06-04 21:28:13 +0300 | [diff] [blame] | 755 | if ( ! empty($_SESSION['__ci_vars'])) |
Andrey Andreev | ecc260e | 2014-01-24 14:20:13 +0200 | [diff] [blame] | 756 | { |
Andrey Andreev | ef41786 | 2014-06-04 21:28:13 +0300 | [diff] [blame] | 757 | foreach ($_SESSION['__ci_vars'] as $key => &$value) |
Andrey Andreev | ecc260e | 2014-01-24 14:20:13 +0200 | [diff] [blame] | 758 | { |
Andrey Andreev | ef41786 | 2014-06-04 21:28:13 +0300 | [diff] [blame] | 759 | is_int($value) OR $flashdata[$key] = $_SESSION[$key]; |
Andrey Andreev | ecc260e | 2014-01-24 14:20:13 +0200 | [diff] [blame] | 760 | } |
| 761 | } |
| 762 | |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 763 | return $flashdata; |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 764 | } |
| 765 | |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 766 | // ------------------------------------------------------------------------ |
| 767 | |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 768 | /** |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 769 | * Set flashdata |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 770 | * |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 771 | * Legacy CI_Session compatibiliy method |
| 772 | * |
| 773 | * @param mixed $data Session data key or an associative array |
| 774 | * @param mixed $value Value to store |
Darren Hill | 5073a37 | 2011-08-31 13:54:19 -0400 | [diff] [blame] | 775 | * @return void |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 776 | */ |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 777 | public function set_flashdata($data, $value = NULL) |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 778 | { |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 779 | $this->set_userdata($data, $value); |
Andrey Andreev | c6e5098 | 2014-10-26 21:27:28 +0200 | [diff] [blame] | 780 | $this->mark_as_flash(is_array($data) ? array_keys($data) : $data); |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 781 | } |
| 782 | |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 783 | // ------------------------------------------------------------------------ |
| 784 | |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 785 | /** |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 786 | * Keep flashdata |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 787 | * |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 788 | * Legacy CI_Session compatibility method |
| 789 | * |
| 790 | * @param mixed $key Session data key(s) |
Darren Hill | 5073a37 | 2011-08-31 13:54:19 -0400 | [diff] [blame] | 791 | * @return void |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 792 | */ |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 793 | public function keep_flashdata($key) |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 794 | { |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 795 | $this->mark_as_flash($key); |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 796 | } |
| 797 | |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 798 | // ------------------------------------------------------------------------ |
| 799 | |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 800 | /** |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 801 | * Temp data (fetch) |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 802 | * |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 803 | * Legacy CI_Session compatibility method |
| 804 | * |
| 805 | * @param string $key Session data key |
| 806 | * @return mixed Session data value or NULL if not found |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 807 | */ |
Andrey Andreev | ecc260e | 2014-01-24 14:20:13 +0200 | [diff] [blame] | 808 | public function tempdata($key = NULL) |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 809 | { |
Andrey Andreev | ecc260e | 2014-01-24 14:20:13 +0200 | [diff] [blame] | 810 | if (isset($key)) |
| 811 | { |
Andrey Andreev | ef41786 | 2014-06-04 21:28:13 +0300 | [diff] [blame] | 812 | return (isset($_SESSION['__ci_vars'], $_SESSION['__ci_vars'][$key], $_SESSION[$key]) && is_int($_SESSION['__ci_vars'][$key])) |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 813 | ? $_SESSION[$key] |
| 814 | : NULL; |
Andrey Andreev | ecc260e | 2014-01-24 14:20:13 +0200 | [diff] [blame] | 815 | } |
| 816 | |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 817 | $tempdata = array(); |
| 818 | |
Andrey Andreev | ef41786 | 2014-06-04 21:28:13 +0300 | [diff] [blame] | 819 | if ( ! empty($_SESSION['__ci_vars'])) |
Andrey Andreev | ecc260e | 2014-01-24 14:20:13 +0200 | [diff] [blame] | 820 | { |
Andrey Andreev | ef41786 | 2014-06-04 21:28:13 +0300 | [diff] [blame] | 821 | foreach ($_SESSION['__ci_vars'] as $key => &$value) |
Andrey Andreev | ecc260e | 2014-01-24 14:20:13 +0200 | [diff] [blame] | 822 | { |
Andrey Andreev | ef41786 | 2014-06-04 21:28:13 +0300 | [diff] [blame] | 823 | is_int($value) && $tempdata[$key] = $_SESSION[$key]; |
Andrey Andreev | ecc260e | 2014-01-24 14:20:13 +0200 | [diff] [blame] | 824 | } |
| 825 | } |
| 826 | |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 827 | return $tempdata; |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 828 | } |
| 829 | |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 830 | // ------------------------------------------------------------------------ |
| 831 | |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 832 | /** |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 833 | * Set tempdata |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 834 | * |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 835 | * Legacy CI_Session compatibility method |
| 836 | * |
| 837 | * @param mixed $data Session data key or an associative array of items |
| 838 | * @param mixed $value Value to store |
| 839 | * @param int $ttl Time-to-live in seconds |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 840 | * @return void |
| 841 | */ |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 842 | public function set_tempdata($data, $value = NULL, $ttl = 300) |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 843 | { |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 844 | $this->set_userdata($data, $value); |
| 845 | $this->mark_as_temp($data, $ttl); |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 846 | } |
| 847 | |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 848 | // ------------------------------------------------------------------------ |
| 849 | |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 850 | /** |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 851 | * Unset tempdata |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 852 | * |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 853 | * Legacy CI_Session compatibility method |
| 854 | * |
| 855 | * @param mixed $data Session data key(s) |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 856 | * @return void |
| 857 | */ |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 858 | public function unset_tempdata($key) |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 859 | { |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 860 | $this->unmark_temp($key); |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 861 | } |
| 862 | |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 863 | } |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 864 | |
| 865 | /* End of file Session.php */ |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 866 | /* Location: ./system/libraries/Session/Session.php */ |