blob: bdcde1e768b44604e14bcbacf7073b597e5cc166 [file] [log] [blame]
Andrey Andreevc5536aa2012-11-01 17:33:58 +02001<?php
Darren Hillc4e266b2011-08-30 15:40:27 -04002/**
3 * CodeIgniter
4 *
Andrey Andreev9ffcee62012-09-05 16:25:16 +03005 * 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 Hillc4e266b2011-08-30 15:40:27 -040018 *
19 * @package CodeIgniter
Andrey Andreev9ffcee62012-09-05 16:25:16 +030020 * @author EllisLab Dev Team
darwinel871754a2014-02-11 17:34:57 +010021 * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (http://ellislab.com/)
Andrey Andreev9ffcee62012-09-05 16:25:16 +030022 * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
Darren Hillc4e266b2011-08-30 15:40:27 -040023 * @link http://codeigniter.com
24 * @since Version 2.0
25 * @filesource
26 */
Andrey Andreevc5536aa2012-11-01 17:33:58 +020027defined('BASEPATH') OR exit('No direct script access allowed');
Darren Hillc4e266b2011-08-30 15:40:27 -040028
Darren Hillc4e266b2011-08-30 15:40:27 -040029/**
Andrey Andreev9ffcee62012-09-05 16:25:16 +030030 * CodeIgniter Session Class
Darren Hillc4e266b2011-08-30 15:40:27 -040031 *
Darren Hillc4e266b2011-08-30 15:40:27 -040032 * @package CodeIgniter
33 * @subpackage Libraries
34 * @category Sessions
Andrey Andreev47a47fb2014-05-31 16:08:30 +030035 * @author Andrey Andreev
Darren Hillc4e266b2011-08-30 15:40:27 -040036 * @link http://codeigniter.com/user_guide/libraries/sessions.html
37 */
Andrey Andreev47a47fb2014-05-31 16:08:30 +030038class CI_Session {
Andrey Andreev9ffcee62012-09-05 16:25:16 +030039
Andrey Andreev47a47fb2014-05-31 16:08:30 +030040 protected $_driver = 'files';
Darren Hillc4e266b2011-08-30 15:40:27 -040041
Andrey Andreev0fa95bd2012-11-01 23:33:14 +020042 // ------------------------------------------------------------------------
43
Darren Hillc4e266b2011-08-30 15:40:27 -040044 /**
Andrey Andreev47a47fb2014-05-31 16:08:30 +030045 * Class constructor
Darren Hillc4e266b2011-08-30 15:40:27 -040046 *
Andrey Andreev47a47fb2014-05-31 16:08:30 +030047 * @param array $params Configuration parameters
Andrey Andreev2e3e2302012-10-09 15:52:34 +030048 * @return void
Darren Hillc4e266b2011-08-30 15:40:27 -040049 */
50 public function __construct(array $params = array())
51 {
Andrey Andreev2e3e2302012-10-09 15:52:34 +030052 // No sessions under CLI
Andrey Andreevf964b162013-11-12 17:04:55 +020053 if (is_cli())
Andrey Andreev2e3e2302012-10-09 15:52:34 +030054 {
Andrey Andreev47a47fb2014-05-31 16:08:30 +030055 log_message('debug', 'Session: Initialization under CLI aborted.');
56 return;
57 }
58 elseif ((bool) ini_get('session.auto_start'))
59 {
60 log_message('error', 'Session: session.auto_start is enabled in php.ini. Aborting.');
61 return;
62 }
63 elseif ( ! empty($params['driver']))
64 {
65 $this->_driver = $params['driver'];
66 unset($params['driver']);
67 }
Andrey Andreev34b1ef52014-05-31 21:23:41 +030068 // Note: Make the autoloader pass sess_* params to this constructor
69 elseif (empty($params) && $driver = config_item('sess_driver'))
70 {
71 $this->_driver = $driver;
72 }
Andrey Andreevac4f4722014-06-02 11:16:32 +030073 // Note: BC workaround
74 elseif (config_item('sess_use_database'))
75 {
76 $this->_driver = 'database';
77 }
Andrey Andreev47a47fb2014-05-31 16:08:30 +030078
79 if (($class = $this->_ci_load_classes($this->_driver)) === FALSE)
80 {
Andrey Andreev2e3e2302012-10-09 15:52:34 +030081 return;
82 }
83
Andrey Andreev47a47fb2014-05-31 16:08:30 +030084 $class = new $class($params);
85 if ($class instanceof SessionHandlerInterface)
Darren Hillc4e266b2011-08-30 15:40:27 -040086 {
Andrey Andreev47a47fb2014-05-31 16:08:30 +030087 if (is_php('5.4'))
Darren Hillc4e266b2011-08-30 15:40:27 -040088 {
Andrey Andreev47a47fb2014-05-31 16:08:30 +030089 session_set_save_handler($class, TRUE);
Darren Hillc4e266b2011-08-30 15:40:27 -040090 }
91 else
92 {
Andrey Andreev47a47fb2014-05-31 16:08:30 +030093 session_set_save_handler(
94 array($class, 'open'),
95 array($class, 'close'),
96 array($class, 'read'),
97 array($class, 'write'),
98 array($class, 'destroy'),
99 array($class, 'gc')
100 );
101
102 register_shutdown_function('session_write_close');
103 }
104 }
105 else
106 {
107 log_message('error', "Session: Driver '".$this->_driver."' doesn't implement SessionHandlerInterface. Aborting.");
108 return;
109 }
110
111 session_start();
112 $this->_ci_init_vars();
113
114 log_message('debug', "Session: Class initialized using '".$this->_driver."' driver.");
115 }
116
117 // ------------------------------------------------------------------------
118
119 protected function _ci_load_classes($driver)
120 {
121 // PHP 5.4 compatibility
122 interface_exists('SessionHandlerInterface', FALSE) OR require_once(BASEPATH.'libraries/Session/SessionHandlerInterface.php');
123
124 $prefix = config_item('subclass_prefix');
125
126 if ( ! class_exists('CI_Session_driver', FALSE))
127 {
128 if (file_exists($file_path = APPPATH.'libraries/Session/Session_driver.php') OR file_exists($file_path = BASEPATH.'libraries/Session/Session_driver.php'))
129 {
130 require_once($file_path);
131 }
132
133 if (file_exists($file_path = APPPATH.'libraries/Session/'.$prefix.'Session_driver.php'))
134 {
135 require_once($file_path);
136 }
137 }
138
139 $class = 'Session_'.$driver.'_driver';
140
141 if ( ! class_exists('CI_'.$class, FALSE))
142 {
143 if (file_exists($file_path = APPPATH.'libraries/Session/drivers/'.$class.'.php') OR file_exists($file_path = BASEPATH.'libraries/Session/drivers/'.$class.'.php'))
144 {
145 require_once($file_path);
146 }
147
148 if ( ! class_exists('CI_'.$class, FALSE))
149 {
150 log_message('error', "Session: Configured driver '".$driver."' was not found. Aborting.");
151 return FALSE;
152 }
153 }
154
155 if ( ! class_exists($prefix.$class) && file_exists($file_path = APPPATH.'libraries/Session/drivers/'.$prefix.$class.'.php'))
156 {
157 require_once($file_path);
158 if (class_exists($prefix.$class, FALSE))
159 {
160 return $prefix.$class;
161 }
162 else
163 {
164 log_message('debug', 'Session: '.$prefix.$class.".php found but it doesn't declare class ".$prefix.$class.'.');
165 }
166 }
167
168 return 'CI_'.$class;
169 }
170
171 // ------------------------------------------------------------------------
172
173 /**
174 * Handle temporary variables
175 *
176 * Clears old "flash" data, marks the new one for deletion and handles
177 * "temp" data deletion.
178 *
179 * @return void
180 */
181 protected function _ci_init_vars()
182 {
183 if ( ! empty($_SESSION['__ci_vars']))
184 {
185 $current_time = time();
186
187 foreach ($_SESSION['__ci_vars'] as $key => &$value)
188 {
189 if ($value === 'new')
190 {
191 $_SESSION['__ci_vars'][$key] = 'old';
192 }
193 // Hacky, but 'old' will (implicitly) always be less than time() ;)
194 // DO NOT move this above the 'new' check!
195 elseif ($value < $current_time)
196 {
197 unset($_SESSION[$key], $_SESSION['__ci_vars'][$key]);
198 }
199 }
200
201 if (empty($_SESSION['__ci_vars']))
202 {
203 unset($_SESSION['__ci_vars']);
Darren Hillc4e266b2011-08-30 15:40:27 -0400204 }
205 }
206 }
207
Andrey Andreev9ffcee62012-09-05 16:25:16 +0300208 // ------------------------------------------------------------------------
209
Darren Hillc4e266b2011-08-30 15:40:27 -0400210 /**
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300211 * Mark as flash
212 *
213 * @param mixed $key Session data key(s)
214 * @return bool
215 */
216 public function mark_as_flash($key)
217 {
218 if (is_array($key))
219 {
220 for ($i = 0, $c = count($key); $i < $c; $i++)
221 {
222 if ( ! isset($_SESSION[$key[$i]]))
223 {
224 return FALSE;
225 }
226 }
227
228 $new = array_fill_keys($key, 'new');
229
230 $_SESSION['__ci_vars'] = isset($_SESSION['__ci_vars'])
231 ? array_merge($_SESSION['__ci_vars'], $new)
232 : $new;
233
234 return TRUE;
235 }
236
237 if ( ! isset($_SESSION[$key]))
238 {
239 return FALSE;
240 }
241
242 $_SESSION['__ci_vars'][$key] = 'new';
243 return TRUE;
244 }
245
246 // ------------------------------------------------------------------------
247
248 /**
249 * Get flash keys
250 *
251 * @return array
252 */
253 public function get_flash_keys()
254 {
255 if ( ! isset($_SESSION['__ci_vars']))
256 {
257 return array();
258 }
259
260 $keys = array();
261 foreach (array_keys($_SESSION['__ci_vars']) as $key)
262 {
263 is_int($_SESSION['__ci_vars'][$key]) OR $keys[] = $key;
264 }
265
266 return $keys;
267 }
268
269 // ------------------------------------------------------------------------
270
271 /**
272 * Unmark flash
273 *
274 * @param mixed $key Session data key(s)
275 * @return void
276 */
277 public function unmark_flash($key)
278 {
279 if (empty($_SESSION['__ci_vars']))
280 {
281 return;
282 }
283
284 is_array($key) OR $key = array($key);
285
286 foreach ($key as $k)
287 {
288 if (isset($_SESSION['__ci_vars'][$k]) && ! is_int($_SESSION['__ci_vars'][$k]))
289 {
290 unset($_SESSION['__ci_vars'][$k]);
291 }
292 }
293
294 if (empty($_SESSION['__ci_vars']))
295 {
296 unset($_SESSION['__ci_vars']);
297 }
298 }
299
300 // ------------------------------------------------------------------------
301
302 /**
303 * Mark as temp
304 *
305 * @param mixed $key Session data key(s)
306 * @param int $ttl Time-to-live in seconds
307 * @return bool
308 */
309 public function mark_as_temp($key, $ttl = 300)
310 {
311 $ttl += time();
312
313 if (is_array($key))
314 {
315 $temp = array();
316
317 foreach ($key as $k => $v)
318 {
319 // Do we have a key => ttl pair, or just a key?
320 if (is_int($k))
321 {
322 $k = $v;
323 $v = $ttl;
324 }
325 else
326 {
327 $v += time();
328 }
329
330 if ( ! isset($_SESSION[$k]))
331 {
332 return FALSE;
333 }
334
335 $temp[$k] = $ts;
336 }
337
338 $_SESSION['__ci_vars'] = isset($_SESSION['__ci_vars'])
339 ? array_merge($_SESSION['__ci_vars'], $temp)
340 : $temp;
341
342 return TRUE;
343 }
344
345 if ( ! isset($_SESSION[$key]))
346 {
347 return FALSE;
348 }
349
350 $_SESSION['__ci_vars'][$key] = $ttl;
351 return TRUE;
352 }
353
354 // ------------------------------------------------------------------------
355
356 /**
357 * Get temp keys
358 *
359 * @return array
360 */
361 public function get_temp_keys()
362 {
363 if ( ! isset($_SESSION['__ci_vars']))
364 {
365 return array();
366 }
367
368 $keys = array();
369 foreach (array_keys($_SESSION['__ci_vars']) as $key)
370 {
371 is_int($_SESSION['__ci_vars'][$key]) && $keys[] = $key;
372 }
373
374 return $keys;
375 }
376
377 // ------------------------------------------------------------------------
378
379 /**
380 * Unmark flash
381 *
382 * @param mixed $key Session data key(s)
383 * @return void
384 */
385 public function unmark_temp($key)
386 {
387 if (empty($_SESSION['__ci_vars']))
388 {
389 return;
390 }
391
392 is_array($key) OR $key = array($key);
393
394 foreach ($key as $k)
395 {
396 if (isset($_SESSION['__ci_vars'][$k]) && is_int($_SESSION['__ci_vars'][$k]))
397 {
398 unset($_SESSION['__ci_vars'][$k]);
399 }
400 }
401
402 if (empty($_SESSION['__ci_vars']))
403 {
404 unset($_SESSION['__ci_vars']);
405 }
406 }
407
408 // ------------------------------------------------------------------------
409
410 /**
411 * __get()
412 *
413 * @param string $key 'session_id' or a session data key
414 * @return mixed
415 */
416 public function __get($key)
417 {
418 // Note: Keep this order the same, just in case somebody wants to
419 // use 'session_id' as a session data key, for whatever reason
420 if (isset($_SESSION[$key]))
421 {
422 return $_SESSION[$key];
423 }
424 elseif ($key === 'session_id')
425 {
426 return session_id();
427 }
428
429 return NULL;
430 }
431
432 // ------------------------------------------------------------------------
433
434 /**
435 * __set()
436 *
437 * @param string $key Session data key
438 * @param mixed $value Session data value
439 * @return void
440 */
441 public function __set($key, $value)
442 {
443 $_SESSION[$key] = $value;
444 }
445
446 // ------------------------------------------------------------------------
447
448 /**
449 * Session destroy
450 *
451 * Legacy CI_Session compatibility method
Darren Hillc4e266b2011-08-30 15:40:27 -0400452 *
Darren Hill5073a372011-08-31 13:54:19 -0400453 * @return void
Darren Hillc4e266b2011-08-30 15:40:27 -0400454 */
455 public function sess_destroy()
456 {
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300457 session_destroy();
Darren Hillc4e266b2011-08-30 15:40:27 -0400458 }
459
Andrey Andreev9ffcee62012-09-05 16:25:16 +0300460 // ------------------------------------------------------------------------
461
Darren Hillc4e266b2011-08-30 15:40:27 -0400462 /**
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300463 * Session regenerate
Darren Hillc4e266b2011-08-30 15:40:27 -0400464 *
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300465 * Legacy CI_Session compatibility method
466 *
467 * @param bool $destroy Destroy old session data flag
Darren Hill5073a372011-08-31 13:54:19 -0400468 * @return void
Darren Hillc4e266b2011-08-30 15:40:27 -0400469 */
Andrey Andreev9ffcee62012-09-05 16:25:16 +0300470 public function sess_regenerate($destroy = FALSE)
Darren Hillc4e266b2011-08-30 15:40:27 -0400471 {
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300472 session_regenerate_id($destroy);
Darren Hillc4e266b2011-08-30 15:40:27 -0400473 }
474
Andrey Andreev9ffcee62012-09-05 16:25:16 +0300475 // ------------------------------------------------------------------------
476
Darren Hillc4e266b2011-08-30 15:40:27 -0400477 /**
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300478 * Get userdata reference
Darren Hillc4e266b2011-08-30 15:40:27 -0400479 *
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300480 * Legacy CI_Session compatibility method
481 *
482 * @returns array
Darren Hillc4e266b2011-08-30 15:40:27 -0400483 */
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300484 public function &get_userdata()
Darren Hillc4e266b2011-08-30 15:40:27 -0400485 {
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300486 return $_SESSION;
487 }
488
489 // ------------------------------------------------------------------------
490
491 /**
492 * Userdata (fetch)
493 *
494 * Legacy CI_Session compatibility method
495 *
496 * @param string $key Session data key
497 * @return mixed Session data value or NULL if not found
498 */
499 public function userdata($key = NULL)
500 {
501 if (isset($key))
Andrey Andreevecc260e2014-01-24 14:20:13 +0200502 {
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300503 return isset($_SESSION[$key]) ? $_SESSION[$key] : NULL;
504 }
505 elseif (empty($_SESSION))
506 {
507 return array();
Andrey Andreevecc260e2014-01-24 14:20:13 +0200508 }
509
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300510 $userdata = array();
511 $_exclude = array_merge(
512 array('__ci_f', '__ci_t'),
513 $this->get_flash_keys(),
514 $this->get_temp_keys()
515 );
Darren Hillc4e266b2011-08-30 15:40:27 -0400516
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300517 foreach (array_keys($_SESSION) as $key)
Darren Hillc4e266b2011-08-30 15:40:27 -0400518 {
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300519 if ( ! in_array($key, $_exclude, TRUE))
Darren Hillc4e266b2011-08-30 15:40:27 -0400520 {
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300521 $userdata[$key] = $_SESSION[$key];
Darren Hillc4e266b2011-08-30 15:40:27 -0400522 }
523 }
524
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300525 return $userdata;
Darren Hillc4e266b2011-08-30 15:40:27 -0400526 }
527
Andrey Andreev9ffcee62012-09-05 16:25:16 +0300528 // ------------------------------------------------------------------------
529
Darren Hillc4e266b2011-08-30 15:40:27 -0400530 /**
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300531 * Set userdata
Darren Hillc4e266b2011-08-30 15:40:27 -0400532 *
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300533 * Legacy CI_Session compatibility method
534 *
535 * @param mixed $data Session data key or an associative array
536 * @param mixed $value Value to store
Darren Hill5073a372011-08-31 13:54:19 -0400537 * @return void
Darren Hillc4e266b2011-08-30 15:40:27 -0400538 */
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300539 public function set_userdata($data, $value = NULL)
Darren Hillc4e266b2011-08-30 15:40:27 -0400540 {
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300541 if (is_array($data))
Darren Hillc4e266b2011-08-30 15:40:27 -0400542 {
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300543 foreach ($data as $key => &$value)
Darren Hillc4e266b2011-08-30 15:40:27 -0400544 {
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300545 $_SESSION[$key] = $value;
Johnathan Croom8d8543d2012-11-25 10:36:57 -0700546 }
547
548 return;
Johnathan Croom4beca5c2012-11-23 18:32:46 -0700549 }
Darren Hillc4e266b2011-08-30 15:40:27 -0400550
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300551 $_SESSION[$data] = $value;
Darren Hillc4e266b2011-08-30 15:40:27 -0400552 }
553
Andrey Andreev9ffcee62012-09-05 16:25:16 +0300554 // ------------------------------------------------------------------------
555
Darren Hillc4e266b2011-08-30 15:40:27 -0400556 /**
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300557 * Unset userdata
Darren Hillc4e266b2011-08-30 15:40:27 -0400558 *
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300559 * Legacy CI_Session compatibility method
560 *
561 * @param mixed $data Session data key(s)
562 * @return void
563 */
564 public function unset_userdata($key)
565 {
566 if (is_array($key))
567 {
568 foreach ($key as $k)
569 {
570 unset($_SESSION[$key]);
571 }
572
573 return;
574 }
575
576 unset($_SESSION[$key]);
577 }
578
579 // ------------------------------------------------------------------------
580
581 /**
582 * All userdata (fetch)
583 *
584 * Legacy CI_Session compatibility method
585 *
586 * @return array $_SESSION, excluding flash data items
587 */
588 public function all_userdata()
589 {
590 return $this->userdata();
591 }
592
593 // ------------------------------------------------------------------------
594
595 /**
596 * Has userdata
597 *
598 * Legacy CI_Session compatibility method
599 *
600 * @param string $key Session data key
601 * @return bool
602 */
603 public function has_userdata($key)
604 {
605 return isset($_SESSION[$key]);
606 }
607
608 // ------------------------------------------------------------------------
609
610 /**
611 * Flashdata (fetch)
612 *
613 * Legacy CI_Session compatibility method
614 *
615 * @param string $key Session data key
616 * @return mixed Session data value or NULL if not found
Darren Hillc4e266b2011-08-30 15:40:27 -0400617 */
Andrey Andreevecc260e2014-01-24 14:20:13 +0200618 public function flashdata($key = NULL)
Darren Hillc4e266b2011-08-30 15:40:27 -0400619 {
Andrey Andreevecc260e2014-01-24 14:20:13 +0200620 if (isset($key))
621 {
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300622 return isset($_SESSION['__ci_f'], $_SESSION['__ci_f'][$key], $_SESSION[$key])
623 ? $_SESSION[$key]
624 : NULL;
Andrey Andreevecc260e2014-01-24 14:20:13 +0200625 }
626
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300627 $flashdata = array();
628
629 if ( ! empty($_SESSION['__ci_f']))
Andrey Andreevecc260e2014-01-24 14:20:13 +0200630 {
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300631 foreach (array_keys($_SESSION['__ci_f']) as $key)
Andrey Andreevecc260e2014-01-24 14:20:13 +0200632 {
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300633 $flashdata[$key] = $_SESSION[$key];
Andrey Andreevecc260e2014-01-24 14:20:13 +0200634 }
635 }
636
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300637 return $flashdata;
Darren Hillc4e266b2011-08-30 15:40:27 -0400638 }
639
Andrey Andreev9ffcee62012-09-05 16:25:16 +0300640 // ------------------------------------------------------------------------
641
Darren Hillc4e266b2011-08-30 15:40:27 -0400642 /**
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300643 * Set flashdata
Darren Hillc4e266b2011-08-30 15:40:27 -0400644 *
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300645 * Legacy CI_Session compatibiliy method
646 *
647 * @param mixed $data Session data key or an associative array
648 * @param mixed $value Value to store
Darren Hill5073a372011-08-31 13:54:19 -0400649 * @return void
Darren Hillc4e266b2011-08-30 15:40:27 -0400650 */
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300651 public function set_flashdata($data, $value = NULL)
Darren Hillc4e266b2011-08-30 15:40:27 -0400652 {
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300653 $this->set_userdata($data, $value);
654 $this->mark_as_flash($data);
Darren Hillc4e266b2011-08-30 15:40:27 -0400655 }
656
Andrey Andreev9ffcee62012-09-05 16:25:16 +0300657 // ------------------------------------------------------------------------
658
Darren Hillc4e266b2011-08-30 15:40:27 -0400659 /**
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300660 * Keep flashdata
Darren Hillc4e266b2011-08-30 15:40:27 -0400661 *
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300662 * Legacy CI_Session compatibility method
663 *
664 * @param mixed $key Session data key(s)
Darren Hill5073a372011-08-31 13:54:19 -0400665 * @return void
Darren Hillc4e266b2011-08-30 15:40:27 -0400666 */
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300667 public function keep_flashdata($key)
Darren Hillc4e266b2011-08-30 15:40:27 -0400668 {
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300669 $this->mark_as_flash($key);
Darren Hillc4e266b2011-08-30 15:40:27 -0400670 }
671
Andrey Andreev9ffcee62012-09-05 16:25:16 +0300672 // ------------------------------------------------------------------------
673
Darren Hillc4e266b2011-08-30 15:40:27 -0400674 /**
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300675 * Temp data (fetch)
Darren Hillc4e266b2011-08-30 15:40:27 -0400676 *
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300677 * Legacy CI_Session compatibility method
678 *
679 * @param string $key Session data key
680 * @return mixed Session data value or NULL if not found
Darren Hillc4e266b2011-08-30 15:40:27 -0400681 */
Andrey Andreevecc260e2014-01-24 14:20:13 +0200682 public function tempdata($key = NULL)
Darren Hillc4e266b2011-08-30 15:40:27 -0400683 {
Andrey Andreevecc260e2014-01-24 14:20:13 +0200684 if (isset($key))
685 {
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300686 return isset($_SESSION['__ci_t'], $_SESSION['__ci_t'][$key], $_SESSION[$key])
687 ? $_SESSION[$key]
688 : NULL;
Andrey Andreevecc260e2014-01-24 14:20:13 +0200689 }
690
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300691 $tempdata = array();
692
693 if ( ! empty($_SESSION['__ci_t']))
Andrey Andreevecc260e2014-01-24 14:20:13 +0200694 {
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300695 foreach (array_keys($_SESSION['__ci_t']) as $key)
Andrey Andreevecc260e2014-01-24 14:20:13 +0200696 {
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300697 $tempdata[$key] = $_SESSION[$key];
Andrey Andreevecc260e2014-01-24 14:20:13 +0200698 }
699 }
700
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300701 return $tempdata;
Darren Hillc4e266b2011-08-30 15:40:27 -0400702 }
703
Andrey Andreev9ffcee62012-09-05 16:25:16 +0300704 // ------------------------------------------------------------------------
705
Darren Hillc4e266b2011-08-30 15:40:27 -0400706 /**
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300707 * Set tempdata
Darren Hillc4e266b2011-08-30 15:40:27 -0400708 *
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300709 * Legacy CI_Session compatibility method
710 *
711 * @param mixed $data Session data key or an associative array of items
712 * @param mixed $value Value to store
713 * @param int $ttl Time-to-live in seconds
Darren Hillc4e266b2011-08-30 15:40:27 -0400714 * @return void
715 */
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300716 public function set_tempdata($data, $value = NULL, $ttl = 300)
Darren Hillc4e266b2011-08-30 15:40:27 -0400717 {
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300718 $this->set_userdata($data, $value);
719 $this->mark_as_temp($data, $ttl);
Darren Hillc4e266b2011-08-30 15:40:27 -0400720 }
721
Andrey Andreev9ffcee62012-09-05 16:25:16 +0300722 // ------------------------------------------------------------------------
723
Darren Hillc4e266b2011-08-30 15:40:27 -0400724 /**
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300725 * Unset tempdata
Darren Hillc4e266b2011-08-30 15:40:27 -0400726 *
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300727 * Legacy CI_Session compatibility method
728 *
729 * @param mixed $data Session data key(s)
Darren Hillc4e266b2011-08-30 15:40:27 -0400730 * @return void
731 */
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300732 public function unset_tempdata($key)
Darren Hillc4e266b2011-08-30 15:40:27 -0400733 {
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300734 $this->unmark_temp($key);
Darren Hillc4e266b2011-08-30 15:40:27 -0400735 }
736
Andrey Andreev9ffcee62012-09-05 16:25:16 +0300737}
Darren Hillc4e266b2011-08-30 15:40:27 -0400738
739/* End of file Session.php */
Andrey Andreev9ffcee62012-09-05 16:25:16 +0300740/* Location: ./system/libraries/Session/Session.php */