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