blob: 518dc28b038112004b7e295700bf8f001661ced8 [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 Andreev47a47fb2014-05-31 16:08:30 +030073
74 if (($class = $this->_ci_load_classes($this->_driver)) === FALSE)
75 {
Andrey Andreev2e3e2302012-10-09 15:52:34 +030076 return;
77 }
78
Andrey Andreev47a47fb2014-05-31 16:08:30 +030079 $class = new $class($params);
80 if ($class instanceof SessionHandlerInterface)
Darren Hillc4e266b2011-08-30 15:40:27 -040081 {
Andrey Andreev47a47fb2014-05-31 16:08:30 +030082 if (is_php('5.4'))
Darren Hillc4e266b2011-08-30 15:40:27 -040083 {
Andrey Andreev47a47fb2014-05-31 16:08:30 +030084 session_set_save_handler($class, TRUE);
Darren Hillc4e266b2011-08-30 15:40:27 -040085 }
86 else
87 {
Andrey Andreev47a47fb2014-05-31 16:08:30 +030088 session_set_save_handler(
89 array($class, 'open'),
90 array($class, 'close'),
91 array($class, 'read'),
92 array($class, 'write'),
93 array($class, 'destroy'),
94 array($class, 'gc')
95 );
96
97 register_shutdown_function('session_write_close');
98 }
99 }
100 else
101 {
102 log_message('error', "Session: Driver '".$this->_driver."' doesn't implement SessionHandlerInterface. Aborting.");
103 return;
104 }
105
106 session_start();
107 $this->_ci_init_vars();
108
109 log_message('debug', "Session: Class initialized using '".$this->_driver."' driver.");
110 }
111
112 // ------------------------------------------------------------------------
113
114 protected function _ci_load_classes($driver)
115 {
116 // PHP 5.4 compatibility
117 interface_exists('SessionHandlerInterface', FALSE) OR require_once(BASEPATH.'libraries/Session/SessionHandlerInterface.php');
118
119 $prefix = config_item('subclass_prefix');
120
121 if ( ! class_exists('CI_Session_driver', FALSE))
122 {
123 if (file_exists($file_path = APPPATH.'libraries/Session/Session_driver.php') OR file_exists($file_path = BASEPATH.'libraries/Session/Session_driver.php'))
124 {
125 require_once($file_path);
126 }
127
128 if (file_exists($file_path = APPPATH.'libraries/Session/'.$prefix.'Session_driver.php'))
129 {
130 require_once($file_path);
131 }
132 }
133
134 $class = 'Session_'.$driver.'_driver';
135
136 if ( ! class_exists('CI_'.$class, FALSE))
137 {
138 if (file_exists($file_path = APPPATH.'libraries/Session/drivers/'.$class.'.php') OR file_exists($file_path = BASEPATH.'libraries/Session/drivers/'.$class.'.php'))
139 {
140 require_once($file_path);
141 }
142
143 if ( ! class_exists('CI_'.$class, FALSE))
144 {
145 log_message('error', "Session: Configured driver '".$driver."' was not found. Aborting.");
146 return FALSE;
147 }
148 }
149
150 if ( ! class_exists($prefix.$class) && file_exists($file_path = APPPATH.'libraries/Session/drivers/'.$prefix.$class.'.php'))
151 {
152 require_once($file_path);
153 if (class_exists($prefix.$class, FALSE))
154 {
155 return $prefix.$class;
156 }
157 else
158 {
159 log_message('debug', 'Session: '.$prefix.$class.".php found but it doesn't declare class ".$prefix.$class.'.');
160 }
161 }
162
163 return 'CI_'.$class;
164 }
165
166 // ------------------------------------------------------------------------
167
168 /**
169 * Handle temporary variables
170 *
171 * Clears old "flash" data, marks the new one for deletion and handles
172 * "temp" data deletion.
173 *
174 * @return void
175 */
176 protected function _ci_init_vars()
177 {
178 if ( ! empty($_SESSION['__ci_vars']))
179 {
180 $current_time = time();
181
182 foreach ($_SESSION['__ci_vars'] as $key => &$value)
183 {
184 if ($value === 'new')
185 {
186 $_SESSION['__ci_vars'][$key] = 'old';
187 }
188 // Hacky, but 'old' will (implicitly) always be less than time() ;)
189 // DO NOT move this above the 'new' check!
190 elseif ($value < $current_time)
191 {
192 unset($_SESSION[$key], $_SESSION['__ci_vars'][$key]);
193 }
194 }
195
196 if (empty($_SESSION['__ci_vars']))
197 {
198 unset($_SESSION['__ci_vars']);
Darren Hillc4e266b2011-08-30 15:40:27 -0400199 }
200 }
201 }
202
Andrey Andreev9ffcee62012-09-05 16:25:16 +0300203 // ------------------------------------------------------------------------
204
Darren Hillc4e266b2011-08-30 15:40:27 -0400205 /**
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300206 * Mark as flash
207 *
208 * @param mixed $key Session data key(s)
209 * @return bool
210 */
211 public function mark_as_flash($key)
212 {
213 if (is_array($key))
214 {
215 for ($i = 0, $c = count($key); $i < $c; $i++)
216 {
217 if ( ! isset($_SESSION[$key[$i]]))
218 {
219 return FALSE;
220 }
221 }
222
223 $new = array_fill_keys($key, 'new');
224
225 $_SESSION['__ci_vars'] = isset($_SESSION['__ci_vars'])
226 ? array_merge($_SESSION['__ci_vars'], $new)
227 : $new;
228
229 return TRUE;
230 }
231
232 if ( ! isset($_SESSION[$key]))
233 {
234 return FALSE;
235 }
236
237 $_SESSION['__ci_vars'][$key] = 'new';
238 return TRUE;
239 }
240
241 // ------------------------------------------------------------------------
242
243 /**
244 * Get flash keys
245 *
246 * @return array
247 */
248 public function get_flash_keys()
249 {
250 if ( ! isset($_SESSION['__ci_vars']))
251 {
252 return array();
253 }
254
255 $keys = array();
256 foreach (array_keys($_SESSION['__ci_vars']) as $key)
257 {
258 is_int($_SESSION['__ci_vars'][$key]) OR $keys[] = $key;
259 }
260
261 return $keys;
262 }
263
264 // ------------------------------------------------------------------------
265
266 /**
267 * Unmark flash
268 *
269 * @param mixed $key Session data key(s)
270 * @return void
271 */
272 public function unmark_flash($key)
273 {
274 if (empty($_SESSION['__ci_vars']))
275 {
276 return;
277 }
278
279 is_array($key) OR $key = array($key);
280
281 foreach ($key as $k)
282 {
283 if (isset($_SESSION['__ci_vars'][$k]) && ! is_int($_SESSION['__ci_vars'][$k]))
284 {
285 unset($_SESSION['__ci_vars'][$k]);
286 }
287 }
288
289 if (empty($_SESSION['__ci_vars']))
290 {
291 unset($_SESSION['__ci_vars']);
292 }
293 }
294
295 // ------------------------------------------------------------------------
296
297 /**
298 * Mark as temp
299 *
300 * @param mixed $key Session data key(s)
301 * @param int $ttl Time-to-live in seconds
302 * @return bool
303 */
304 public function mark_as_temp($key, $ttl = 300)
305 {
306 $ttl += time();
307
308 if (is_array($key))
309 {
310 $temp = array();
311
312 foreach ($key as $k => $v)
313 {
314 // Do we have a key => ttl pair, or just a key?
315 if (is_int($k))
316 {
317 $k = $v;
318 $v = $ttl;
319 }
320 else
321 {
322 $v += time();
323 }
324
325 if ( ! isset($_SESSION[$k]))
326 {
327 return FALSE;
328 }
329
330 $temp[$k] = $ts;
331 }
332
333 $_SESSION['__ci_vars'] = isset($_SESSION['__ci_vars'])
334 ? array_merge($_SESSION['__ci_vars'], $temp)
335 : $temp;
336
337 return TRUE;
338 }
339
340 if ( ! isset($_SESSION[$key]))
341 {
342 return FALSE;
343 }
344
345 $_SESSION['__ci_vars'][$key] = $ttl;
346 return TRUE;
347 }
348
349 // ------------------------------------------------------------------------
350
351 /**
352 * Get temp keys
353 *
354 * @return array
355 */
356 public function get_temp_keys()
357 {
358 if ( ! isset($_SESSION['__ci_vars']))
359 {
360 return array();
361 }
362
363 $keys = array();
364 foreach (array_keys($_SESSION['__ci_vars']) as $key)
365 {
366 is_int($_SESSION['__ci_vars'][$key]) && $keys[] = $key;
367 }
368
369 return $keys;
370 }
371
372 // ------------------------------------------------------------------------
373
374 /**
375 * Unmark flash
376 *
377 * @param mixed $key Session data key(s)
378 * @return void
379 */
380 public function unmark_temp($key)
381 {
382 if (empty($_SESSION['__ci_vars']))
383 {
384 return;
385 }
386
387 is_array($key) OR $key = array($key);
388
389 foreach ($key as $k)
390 {
391 if (isset($_SESSION['__ci_vars'][$k]) && is_int($_SESSION['__ci_vars'][$k]))
392 {
393 unset($_SESSION['__ci_vars'][$k]);
394 }
395 }
396
397 if (empty($_SESSION['__ci_vars']))
398 {
399 unset($_SESSION['__ci_vars']);
400 }
401 }
402
403 // ------------------------------------------------------------------------
404
405 /**
406 * __get()
407 *
408 * @param string $key 'session_id' or a session data key
409 * @return mixed
410 */
411 public function __get($key)
412 {
413 // Note: Keep this order the same, just in case somebody wants to
414 // use 'session_id' as a session data key, for whatever reason
415 if (isset($_SESSION[$key]))
416 {
417 return $_SESSION[$key];
418 }
419 elseif ($key === 'session_id')
420 {
421 return session_id();
422 }
423
424 return NULL;
425 }
426
427 // ------------------------------------------------------------------------
428
429 /**
430 * __set()
431 *
432 * @param string $key Session data key
433 * @param mixed $value Session data value
434 * @return void
435 */
436 public function __set($key, $value)
437 {
438 $_SESSION[$key] = $value;
439 }
440
441 // ------------------------------------------------------------------------
442
443 /**
444 * Session destroy
445 *
446 * Legacy CI_Session compatibility method
Darren Hillc4e266b2011-08-30 15:40:27 -0400447 *
Darren Hill5073a372011-08-31 13:54:19 -0400448 * @return void
Darren Hillc4e266b2011-08-30 15:40:27 -0400449 */
450 public function sess_destroy()
451 {
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300452 session_destroy();
Darren Hillc4e266b2011-08-30 15:40:27 -0400453 }
454
Andrey Andreev9ffcee62012-09-05 16:25:16 +0300455 // ------------------------------------------------------------------------
456
Darren Hillc4e266b2011-08-30 15:40:27 -0400457 /**
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300458 * Session regenerate
Darren Hillc4e266b2011-08-30 15:40:27 -0400459 *
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300460 * Legacy CI_Session compatibility method
461 *
462 * @param bool $destroy Destroy old session data flag
Darren Hill5073a372011-08-31 13:54:19 -0400463 * @return void
Darren Hillc4e266b2011-08-30 15:40:27 -0400464 */
Andrey Andreev9ffcee62012-09-05 16:25:16 +0300465 public function sess_regenerate($destroy = FALSE)
Darren Hillc4e266b2011-08-30 15:40:27 -0400466 {
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300467 session_regenerate_id($destroy);
Darren Hillc4e266b2011-08-30 15:40:27 -0400468 }
469
Andrey Andreev9ffcee62012-09-05 16:25:16 +0300470 // ------------------------------------------------------------------------
471
Darren Hillc4e266b2011-08-30 15:40:27 -0400472 /**
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300473 * Get userdata reference
Darren Hillc4e266b2011-08-30 15:40:27 -0400474 *
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300475 * Legacy CI_Session compatibility method
476 *
477 * @returns array
Darren Hillc4e266b2011-08-30 15:40:27 -0400478 */
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300479 public function &get_userdata()
Darren Hillc4e266b2011-08-30 15:40:27 -0400480 {
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300481 return $_SESSION;
482 }
483
484 // ------------------------------------------------------------------------
485
486 /**
487 * Userdata (fetch)
488 *
489 * Legacy CI_Session compatibility method
490 *
491 * @param string $key Session data key
492 * @return mixed Session data value or NULL if not found
493 */
494 public function userdata($key = NULL)
495 {
496 if (isset($key))
Andrey Andreevecc260e2014-01-24 14:20:13 +0200497 {
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300498 return isset($_SESSION[$key]) ? $_SESSION[$key] : NULL;
499 }
500 elseif (empty($_SESSION))
501 {
502 return array();
Andrey Andreevecc260e2014-01-24 14:20:13 +0200503 }
504
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300505 $userdata = array();
506 $_exclude = array_merge(
507 array('__ci_f', '__ci_t'),
508 $this->get_flash_keys(),
509 $this->get_temp_keys()
510 );
Darren Hillc4e266b2011-08-30 15:40:27 -0400511
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300512 foreach (array_keys($_SESSION) as $key)
Darren Hillc4e266b2011-08-30 15:40:27 -0400513 {
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300514 if ( ! in_array($key, $_exclude, TRUE))
Darren Hillc4e266b2011-08-30 15:40:27 -0400515 {
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300516 $userdata[$key] = $_SESSION[$key];
Darren Hillc4e266b2011-08-30 15:40:27 -0400517 }
518 }
519
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300520 return $userdata;
Darren Hillc4e266b2011-08-30 15:40:27 -0400521 }
522
Andrey Andreev9ffcee62012-09-05 16:25:16 +0300523 // ------------------------------------------------------------------------
524
Darren Hillc4e266b2011-08-30 15:40:27 -0400525 /**
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300526 * Set userdata
Darren Hillc4e266b2011-08-30 15:40:27 -0400527 *
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300528 * Legacy CI_Session compatibility method
529 *
530 * @param mixed $data Session data key or an associative array
531 * @param mixed $value Value to store
Darren Hill5073a372011-08-31 13:54:19 -0400532 * @return void
Darren Hillc4e266b2011-08-30 15:40:27 -0400533 */
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300534 public function set_userdata($data, $value = NULL)
Darren Hillc4e266b2011-08-30 15:40:27 -0400535 {
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300536 if (is_array($data))
Darren Hillc4e266b2011-08-30 15:40:27 -0400537 {
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300538 foreach ($data as $key => &$value)
Darren Hillc4e266b2011-08-30 15:40:27 -0400539 {
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300540 $_SESSION[$key] = $value;
Johnathan Croom8d8543d2012-11-25 10:36:57 -0700541 }
542
543 return;
Johnathan Croom4beca5c2012-11-23 18:32:46 -0700544 }
Darren Hillc4e266b2011-08-30 15:40:27 -0400545
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300546 $_SESSION[$data] = $value;
Darren Hillc4e266b2011-08-30 15:40:27 -0400547 }
548
Andrey Andreev9ffcee62012-09-05 16:25:16 +0300549 // ------------------------------------------------------------------------
550
Darren Hillc4e266b2011-08-30 15:40:27 -0400551 /**
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300552 * Unset userdata
Darren Hillc4e266b2011-08-30 15:40:27 -0400553 *
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300554 * Legacy CI_Session compatibility method
555 *
556 * @param mixed $data Session data key(s)
557 * @return void
558 */
559 public function unset_userdata($key)
560 {
561 if (is_array($key))
562 {
563 foreach ($key as $k)
564 {
565 unset($_SESSION[$key]);
566 }
567
568 return;
569 }
570
571 unset($_SESSION[$key]);
572 }
573
574 // ------------------------------------------------------------------------
575
576 /**
577 * All userdata (fetch)
578 *
579 * Legacy CI_Session compatibility method
580 *
581 * @return array $_SESSION, excluding flash data items
582 */
583 public function all_userdata()
584 {
585 return $this->userdata();
586 }
587
588 // ------------------------------------------------------------------------
589
590 /**
591 * Has userdata
592 *
593 * Legacy CI_Session compatibility method
594 *
595 * @param string $key Session data key
596 * @return bool
597 */
598 public function has_userdata($key)
599 {
600 return isset($_SESSION[$key]);
601 }
602
603 // ------------------------------------------------------------------------
604
605 /**
606 * Flashdata (fetch)
607 *
608 * Legacy CI_Session compatibility method
609 *
610 * @param string $key Session data key
611 * @return mixed Session data value or NULL if not found
Darren Hillc4e266b2011-08-30 15:40:27 -0400612 */
Andrey Andreevecc260e2014-01-24 14:20:13 +0200613 public function flashdata($key = NULL)
Darren Hillc4e266b2011-08-30 15:40:27 -0400614 {
Andrey Andreevecc260e2014-01-24 14:20:13 +0200615 if (isset($key))
616 {
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300617 return isset($_SESSION['__ci_f'], $_SESSION['__ci_f'][$key], $_SESSION[$key])
618 ? $_SESSION[$key]
619 : NULL;
Andrey Andreevecc260e2014-01-24 14:20:13 +0200620 }
621
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300622 $flashdata = array();
623
624 if ( ! empty($_SESSION['__ci_f']))
Andrey Andreevecc260e2014-01-24 14:20:13 +0200625 {
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300626 foreach (array_keys($_SESSION['__ci_f']) as $key)
Andrey Andreevecc260e2014-01-24 14:20:13 +0200627 {
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300628 $flashdata[$key] = $_SESSION[$key];
Andrey Andreevecc260e2014-01-24 14:20:13 +0200629 }
630 }
631
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300632 return $flashdata;
Darren Hillc4e266b2011-08-30 15:40:27 -0400633 }
634
Andrey Andreev9ffcee62012-09-05 16:25:16 +0300635 // ------------------------------------------------------------------------
636
Darren Hillc4e266b2011-08-30 15:40:27 -0400637 /**
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300638 * Set flashdata
Darren Hillc4e266b2011-08-30 15:40:27 -0400639 *
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300640 * Legacy CI_Session compatibiliy method
641 *
642 * @param mixed $data Session data key or an associative array
643 * @param mixed $value Value to store
Darren Hill5073a372011-08-31 13:54:19 -0400644 * @return void
Darren Hillc4e266b2011-08-30 15:40:27 -0400645 */
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300646 public function set_flashdata($data, $value = NULL)
Darren Hillc4e266b2011-08-30 15:40:27 -0400647 {
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300648 $this->set_userdata($data, $value);
649 $this->mark_as_flash($data);
Darren Hillc4e266b2011-08-30 15:40:27 -0400650 }
651
Andrey Andreev9ffcee62012-09-05 16:25:16 +0300652 // ------------------------------------------------------------------------
653
Darren Hillc4e266b2011-08-30 15:40:27 -0400654 /**
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300655 * Keep flashdata
Darren Hillc4e266b2011-08-30 15:40:27 -0400656 *
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300657 * Legacy CI_Session compatibility method
658 *
659 * @param mixed $key Session data key(s)
Darren Hill5073a372011-08-31 13:54:19 -0400660 * @return void
Darren Hillc4e266b2011-08-30 15:40:27 -0400661 */
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300662 public function keep_flashdata($key)
Darren Hillc4e266b2011-08-30 15:40:27 -0400663 {
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300664 $this->mark_as_flash($key);
Darren Hillc4e266b2011-08-30 15:40:27 -0400665 }
666
Andrey Andreev9ffcee62012-09-05 16:25:16 +0300667 // ------------------------------------------------------------------------
668
Darren Hillc4e266b2011-08-30 15:40:27 -0400669 /**
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300670 * Temp data (fetch)
Darren Hillc4e266b2011-08-30 15:40:27 -0400671 *
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300672 * Legacy CI_Session compatibility method
673 *
674 * @param string $key Session data key
675 * @return mixed Session data value or NULL if not found
Darren Hillc4e266b2011-08-30 15:40:27 -0400676 */
Andrey Andreevecc260e2014-01-24 14:20:13 +0200677 public function tempdata($key = NULL)
Darren Hillc4e266b2011-08-30 15:40:27 -0400678 {
Andrey Andreevecc260e2014-01-24 14:20:13 +0200679 if (isset($key))
680 {
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300681 return isset($_SESSION['__ci_t'], $_SESSION['__ci_t'][$key], $_SESSION[$key])
682 ? $_SESSION[$key]
683 : NULL;
Andrey Andreevecc260e2014-01-24 14:20:13 +0200684 }
685
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300686 $tempdata = array();
687
688 if ( ! empty($_SESSION['__ci_t']))
Andrey Andreevecc260e2014-01-24 14:20:13 +0200689 {
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300690 foreach (array_keys($_SESSION['__ci_t']) as $key)
Andrey Andreevecc260e2014-01-24 14:20:13 +0200691 {
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300692 $tempdata[$key] = $_SESSION[$key];
Andrey Andreevecc260e2014-01-24 14:20:13 +0200693 }
694 }
695
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300696 return $tempdata;
Darren Hillc4e266b2011-08-30 15:40:27 -0400697 }
698
Andrey Andreev9ffcee62012-09-05 16:25:16 +0300699 // ------------------------------------------------------------------------
700
Darren Hillc4e266b2011-08-30 15:40:27 -0400701 /**
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300702 * Set tempdata
Darren Hillc4e266b2011-08-30 15:40:27 -0400703 *
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300704 * Legacy CI_Session compatibility method
705 *
706 * @param mixed $data Session data key or an associative array of items
707 * @param mixed $value Value to store
708 * @param int $ttl Time-to-live in seconds
Darren Hillc4e266b2011-08-30 15:40:27 -0400709 * @return void
710 */
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300711 public function set_tempdata($data, $value = NULL, $ttl = 300)
Darren Hillc4e266b2011-08-30 15:40:27 -0400712 {
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300713 $this->set_userdata($data, $value);
714 $this->mark_as_temp($data, $ttl);
Darren Hillc4e266b2011-08-30 15:40:27 -0400715 }
716
Andrey Andreev9ffcee62012-09-05 16:25:16 +0300717 // ------------------------------------------------------------------------
718
Darren Hillc4e266b2011-08-30 15:40:27 -0400719 /**
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300720 * Unset tempdata
Darren Hillc4e266b2011-08-30 15:40:27 -0400721 *
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300722 * Legacy CI_Session compatibility method
723 *
724 * @param mixed $data Session data key(s)
Darren Hillc4e266b2011-08-30 15:40:27 -0400725 * @return void
726 */
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300727 public function unset_tempdata($key)
Darren Hillc4e266b2011-08-30 15:40:27 -0400728 {
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300729 $this->unmark_temp($key);
Darren Hillc4e266b2011-08-30 15:40:27 -0400730 }
731
Andrey Andreev9ffcee62012-09-05 16:25:16 +0300732}
Darren Hillc4e266b2011-08-30 15:40:27 -0400733
734/* End of file Session.php */
Andrey Andreev9ffcee62012-09-05 16:25:16 +0300735/* Location: ./system/libraries/Session/Session.php */