blob: 0d444e8cac5109483d075c3f4c773c7d1fbbd93e [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
53 // No sessions under CLI
Andrey Andreevf964b162013-11-12 17:04:55 +020054 if (is_cli())
Andrey Andreev2e3e2302012-10-09 15:52:34 +030055 {
Andrey Andreev47a47fb2014-05-31 16:08:30 +030056 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 }
69
70 if (($class = $this->_ci_load_classes($this->_driver)) === FALSE)
71 {
Andrey Andreev2e3e2302012-10-09 15:52:34 +030072 return;
73 }
74
Andrey Andreev47a47fb2014-05-31 16:08:30 +030075 $class = new $class($params);
76 if ($class instanceof SessionHandlerInterface)
Darren Hillc4e266b2011-08-30 15:40:27 -040077 {
Andrey Andreev47a47fb2014-05-31 16:08:30 +030078 if (is_php('5.4'))
Darren Hillc4e266b2011-08-30 15:40:27 -040079 {
Andrey Andreev47a47fb2014-05-31 16:08:30 +030080 session_set_save_handler($class, TRUE);
Darren Hillc4e266b2011-08-30 15:40:27 -040081 }
82 else
83 {
Andrey Andreev47a47fb2014-05-31 16:08:30 +030084 session_set_save_handler(
85 array($class, 'open'),
86 array($class, 'close'),
87 array($class, 'read'),
88 array($class, 'write'),
89 array($class, 'destroy'),
90 array($class, 'gc')
91 );
92
93 register_shutdown_function('session_write_close');
94 }
95 }
96 else
97 {
98 log_message('error', "Session: Driver '".$this->_driver."' doesn't implement SessionHandlerInterface. Aborting.");
99 return;
100 }
101
102 session_start();
103 $this->_ci_init_vars();
104
105 log_message('debug', "Session: Class initialized using '".$this->_driver."' driver.");
106 }
107
108 // ------------------------------------------------------------------------
109
110 protected function _ci_load_classes($driver)
111 {
112 // PHP 5.4 compatibility
113 interface_exists('SessionHandlerInterface', FALSE) OR require_once(BASEPATH.'libraries/Session/SessionHandlerInterface.php');
114
115 $prefix = config_item('subclass_prefix');
116
117 if ( ! class_exists('CI_Session_driver', FALSE))
118 {
119 if (file_exists($file_path = APPPATH.'libraries/Session/Session_driver.php') OR file_exists($file_path = BASEPATH.'libraries/Session/Session_driver.php'))
120 {
121 require_once($file_path);
122 }
123
124 if (file_exists($file_path = APPPATH.'libraries/Session/'.$prefix.'Session_driver.php'))
125 {
126 require_once($file_path);
127 }
128 }
129
130 $class = 'Session_'.$driver.'_driver';
131
132 if ( ! class_exists('CI_'.$class, FALSE))
133 {
134 if (file_exists($file_path = APPPATH.'libraries/Session/drivers/'.$class.'.php') OR file_exists($file_path = BASEPATH.'libraries/Session/drivers/'.$class.'.php'))
135 {
136 require_once($file_path);
137 }
138
139 if ( ! class_exists('CI_'.$class, FALSE))
140 {
141 log_message('error', "Session: Configured driver '".$driver."' was not found. Aborting.");
142 return FALSE;
143 }
144 }
145
146 if ( ! class_exists($prefix.$class) && file_exists($file_path = APPPATH.'libraries/Session/drivers/'.$prefix.$class.'.php'))
147 {
148 require_once($file_path);
149 if (class_exists($prefix.$class, FALSE))
150 {
151 return $prefix.$class;
152 }
153 else
154 {
155 log_message('debug', 'Session: '.$prefix.$class.".php found but it doesn't declare class ".$prefix.$class.'.');
156 }
157 }
158
159 return 'CI_'.$class;
160 }
161
162 // ------------------------------------------------------------------------
163
164 /**
165 * Handle temporary variables
166 *
167 * Clears old "flash" data, marks the new one for deletion and handles
168 * "temp" data deletion.
169 *
170 * @return void
171 */
172 protected function _ci_init_vars()
173 {
174 if ( ! empty($_SESSION['__ci_vars']))
175 {
176 $current_time = time();
177
178 foreach ($_SESSION['__ci_vars'] as $key => &$value)
179 {
180 if ($value === 'new')
181 {
182 $_SESSION['__ci_vars'][$key] = 'old';
183 }
184 // Hacky, but 'old' will (implicitly) always be less than time() ;)
185 // DO NOT move this above the 'new' check!
186 elseif ($value < $current_time)
187 {
188 unset($_SESSION[$key], $_SESSION['__ci_vars'][$key]);
189 }
190 }
191
192 if (empty($_SESSION['__ci_vars']))
193 {
194 unset($_SESSION['__ci_vars']);
Darren Hillc4e266b2011-08-30 15:40:27 -0400195 }
196 }
197 }
198
Andrey Andreev9ffcee62012-09-05 16:25:16 +0300199 // ------------------------------------------------------------------------
200
Darren Hillc4e266b2011-08-30 15:40:27 -0400201 /**
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300202 * Mark as flash
203 *
204 * @param mixed $key Session data key(s)
205 * @return bool
206 */
207 public function mark_as_flash($key)
208 {
209 if (is_array($key))
210 {
211 for ($i = 0, $c = count($key); $i < $c; $i++)
212 {
213 if ( ! isset($_SESSION[$key[$i]]))
214 {
215 return FALSE;
216 }
217 }
218
219 $new = array_fill_keys($key, 'new');
220
221 $_SESSION['__ci_vars'] = isset($_SESSION['__ci_vars'])
222 ? array_merge($_SESSION['__ci_vars'], $new)
223 : $new;
224
225 return TRUE;
226 }
227
228 if ( ! isset($_SESSION[$key]))
229 {
230 return FALSE;
231 }
232
233 $_SESSION['__ci_vars'][$key] = 'new';
234 return TRUE;
235 }
236
237 // ------------------------------------------------------------------------
238
239 /**
240 * Get flash keys
241 *
242 * @return array
243 */
244 public function get_flash_keys()
245 {
246 if ( ! isset($_SESSION['__ci_vars']))
247 {
248 return array();
249 }
250
251 $keys = array();
252 foreach (array_keys($_SESSION['__ci_vars']) as $key)
253 {
254 is_int($_SESSION['__ci_vars'][$key]) OR $keys[] = $key;
255 }
256
257 return $keys;
258 }
259
260 // ------------------------------------------------------------------------
261
262 /**
263 * Unmark flash
264 *
265 * @param mixed $key Session data key(s)
266 * @return void
267 */
268 public function unmark_flash($key)
269 {
270 if (empty($_SESSION['__ci_vars']))
271 {
272 return;
273 }
274
275 is_array($key) OR $key = array($key);
276
277 foreach ($key as $k)
278 {
279 if (isset($_SESSION['__ci_vars'][$k]) && ! is_int($_SESSION['__ci_vars'][$k]))
280 {
281 unset($_SESSION['__ci_vars'][$k]);
282 }
283 }
284
285 if (empty($_SESSION['__ci_vars']))
286 {
287 unset($_SESSION['__ci_vars']);
288 }
289 }
290
291 // ------------------------------------------------------------------------
292
293 /**
294 * Mark as temp
295 *
296 * @param mixed $key Session data key(s)
297 * @param int $ttl Time-to-live in seconds
298 * @return bool
299 */
300 public function mark_as_temp($key, $ttl = 300)
301 {
302 $ttl += time();
303
304 if (is_array($key))
305 {
306 $temp = array();
307
308 foreach ($key as $k => $v)
309 {
310 // Do we have a key => ttl pair, or just a key?
311 if (is_int($k))
312 {
313 $k = $v;
314 $v = $ttl;
315 }
316 else
317 {
318 $v += time();
319 }
320
321 if ( ! isset($_SESSION[$k]))
322 {
323 return FALSE;
324 }
325
326 $temp[$k] = $ts;
327 }
328
329 $_SESSION['__ci_vars'] = isset($_SESSION['__ci_vars'])
330 ? array_merge($_SESSION['__ci_vars'], $temp)
331 : $temp;
332
333 return TRUE;
334 }
335
336 if ( ! isset($_SESSION[$key]))
337 {
338 return FALSE;
339 }
340
341 $_SESSION['__ci_vars'][$key] = $ttl;
342 return TRUE;
343 }
344
345 // ------------------------------------------------------------------------
346
347 /**
348 * Get temp keys
349 *
350 * @return array
351 */
352 public function get_temp_keys()
353 {
354 if ( ! isset($_SESSION['__ci_vars']))
355 {
356 return array();
357 }
358
359 $keys = array();
360 foreach (array_keys($_SESSION['__ci_vars']) as $key)
361 {
362 is_int($_SESSION['__ci_vars'][$key]) && $keys[] = $key;
363 }
364
365 return $keys;
366 }
367
368 // ------------------------------------------------------------------------
369
370 /**
371 * Unmark flash
372 *
373 * @param mixed $key Session data key(s)
374 * @return void
375 */
376 public function unmark_temp($key)
377 {
378 if (empty($_SESSION['__ci_vars']))
379 {
380 return;
381 }
382
383 is_array($key) OR $key = array($key);
384
385 foreach ($key as $k)
386 {
387 if (isset($_SESSION['__ci_vars'][$k]) && is_int($_SESSION['__ci_vars'][$k]))
388 {
389 unset($_SESSION['__ci_vars'][$k]);
390 }
391 }
392
393 if (empty($_SESSION['__ci_vars']))
394 {
395 unset($_SESSION['__ci_vars']);
396 }
397 }
398
399 // ------------------------------------------------------------------------
400
401 /**
402 * __get()
403 *
404 * @param string $key 'session_id' or a session data key
405 * @return mixed
406 */
407 public function __get($key)
408 {
409 // Note: Keep this order the same, just in case somebody wants to
410 // use 'session_id' as a session data key, for whatever reason
411 if (isset($_SESSION[$key]))
412 {
413 return $_SESSION[$key];
414 }
415 elseif ($key === 'session_id')
416 {
417 return session_id();
418 }
419
420 return NULL;
421 }
422
423 // ------------------------------------------------------------------------
424
425 /**
426 * __set()
427 *
428 * @param string $key Session data key
429 * @param mixed $value Session data value
430 * @return void
431 */
432 public function __set($key, $value)
433 {
434 $_SESSION[$key] = $value;
435 }
436
437 // ------------------------------------------------------------------------
438
439 /**
440 * Session destroy
441 *
442 * Legacy CI_Session compatibility method
Darren Hillc4e266b2011-08-30 15:40:27 -0400443 *
Darren Hill5073a372011-08-31 13:54:19 -0400444 * @return void
Darren Hillc4e266b2011-08-30 15:40:27 -0400445 */
446 public function sess_destroy()
447 {
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300448 session_destroy();
Darren Hillc4e266b2011-08-30 15:40:27 -0400449 }
450
Andrey Andreev9ffcee62012-09-05 16:25:16 +0300451 // ------------------------------------------------------------------------
452
Darren Hillc4e266b2011-08-30 15:40:27 -0400453 /**
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300454 * Session regenerate
Darren Hillc4e266b2011-08-30 15:40:27 -0400455 *
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300456 * Legacy CI_Session compatibility method
457 *
458 * @param bool $destroy Destroy old session data flag
Darren Hill5073a372011-08-31 13:54:19 -0400459 * @return void
Darren Hillc4e266b2011-08-30 15:40:27 -0400460 */
Andrey Andreev9ffcee62012-09-05 16:25:16 +0300461 public function sess_regenerate($destroy = FALSE)
Darren Hillc4e266b2011-08-30 15:40:27 -0400462 {
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300463 session_regenerate_id($destroy);
Darren Hillc4e266b2011-08-30 15:40:27 -0400464 }
465
Andrey Andreev9ffcee62012-09-05 16:25:16 +0300466 // ------------------------------------------------------------------------
467
Darren Hillc4e266b2011-08-30 15:40:27 -0400468 /**
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300469 * Get userdata reference
Darren Hillc4e266b2011-08-30 15:40:27 -0400470 *
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300471 * Legacy CI_Session compatibility method
472 *
473 * @returns array
Darren Hillc4e266b2011-08-30 15:40:27 -0400474 */
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300475 public function &get_userdata()
Darren Hillc4e266b2011-08-30 15:40:27 -0400476 {
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300477 return $_SESSION;
478 }
479
480 // ------------------------------------------------------------------------
481
482 /**
483 * Userdata (fetch)
484 *
485 * Legacy CI_Session compatibility method
486 *
487 * @param string $key Session data key
488 * @return mixed Session data value or NULL if not found
489 */
490 public function userdata($key = NULL)
491 {
492 if (isset($key))
Andrey Andreevecc260e2014-01-24 14:20:13 +0200493 {
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300494 return isset($_SESSION[$key]) ? $_SESSION[$key] : NULL;
495 }
496 elseif (empty($_SESSION))
497 {
498 return array();
Andrey Andreevecc260e2014-01-24 14:20:13 +0200499 }
500
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300501 $userdata = array();
502 $_exclude = array_merge(
503 array('__ci_f', '__ci_t'),
504 $this->get_flash_keys(),
505 $this->get_temp_keys()
506 );
Darren Hillc4e266b2011-08-30 15:40:27 -0400507
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300508 foreach (array_keys($_SESSION) as $key)
Darren Hillc4e266b2011-08-30 15:40:27 -0400509 {
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300510 if ( ! in_array($key, $_exclude, TRUE))
Darren Hillc4e266b2011-08-30 15:40:27 -0400511 {
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300512 $userdata[$key] = $_SESSION[$key];
Darren Hillc4e266b2011-08-30 15:40:27 -0400513 }
514 }
515
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300516 return $userdata;
Darren Hillc4e266b2011-08-30 15:40:27 -0400517 }
518
Andrey Andreev9ffcee62012-09-05 16:25:16 +0300519 // ------------------------------------------------------------------------
520
Darren Hillc4e266b2011-08-30 15:40:27 -0400521 /**
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300522 * Set userdata
Darren Hillc4e266b2011-08-30 15:40:27 -0400523 *
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300524 * Legacy CI_Session compatibility method
525 *
526 * @param mixed $data Session data key or an associative array
527 * @param mixed $value Value to store
Darren Hill5073a372011-08-31 13:54:19 -0400528 * @return void
Darren Hillc4e266b2011-08-30 15:40:27 -0400529 */
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300530 public function set_userdata($data, $value = NULL)
Darren Hillc4e266b2011-08-30 15:40:27 -0400531 {
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300532 if (is_array($data))
Darren Hillc4e266b2011-08-30 15:40:27 -0400533 {
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300534 foreach ($data as $key => &$value)
Darren Hillc4e266b2011-08-30 15:40:27 -0400535 {
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300536 $_SESSION[$key] = $value;
Johnathan Croom8d8543d2012-11-25 10:36:57 -0700537 }
538
539 return;
Johnathan Croom4beca5c2012-11-23 18:32:46 -0700540 }
Darren Hillc4e266b2011-08-30 15:40:27 -0400541
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300542 $_SESSION[$data] = $value;
Darren Hillc4e266b2011-08-30 15:40:27 -0400543 }
544
Andrey Andreev9ffcee62012-09-05 16:25:16 +0300545 // ------------------------------------------------------------------------
546
Darren Hillc4e266b2011-08-30 15:40:27 -0400547 /**
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300548 * Unset userdata
Darren Hillc4e266b2011-08-30 15:40:27 -0400549 *
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300550 * Legacy CI_Session compatibility method
551 *
552 * @param mixed $data Session data key(s)
553 * @return void
554 */
555 public function unset_userdata($key)
556 {
557 if (is_array($key))
558 {
559 foreach ($key as $k)
560 {
561 unset($_SESSION[$key]);
562 }
563
564 return;
565 }
566
567 unset($_SESSION[$key]);
568 }
569
570 // ------------------------------------------------------------------------
571
572 /**
573 * All userdata (fetch)
574 *
575 * Legacy CI_Session compatibility method
576 *
577 * @return array $_SESSION, excluding flash data items
578 */
579 public function all_userdata()
580 {
581 return $this->userdata();
582 }
583
584 // ------------------------------------------------------------------------
585
586 /**
587 * Has userdata
588 *
589 * Legacy CI_Session compatibility method
590 *
591 * @param string $key Session data key
592 * @return bool
593 */
594 public function has_userdata($key)
595 {
596 return isset($_SESSION[$key]);
597 }
598
599 // ------------------------------------------------------------------------
600
601 /**
602 * Flashdata (fetch)
603 *
604 * Legacy CI_Session compatibility method
605 *
606 * @param string $key Session data key
607 * @return mixed Session data value or NULL if not found
Darren Hillc4e266b2011-08-30 15:40:27 -0400608 */
Andrey Andreevecc260e2014-01-24 14:20:13 +0200609 public function flashdata($key = NULL)
Darren Hillc4e266b2011-08-30 15:40:27 -0400610 {
Andrey Andreevecc260e2014-01-24 14:20:13 +0200611 if (isset($key))
612 {
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300613 return isset($_SESSION['__ci_f'], $_SESSION['__ci_f'][$key], $_SESSION[$key])
614 ? $_SESSION[$key]
615 : NULL;
Andrey Andreevecc260e2014-01-24 14:20:13 +0200616 }
617
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300618 $flashdata = array();
619
620 if ( ! empty($_SESSION['__ci_f']))
Andrey Andreevecc260e2014-01-24 14:20:13 +0200621 {
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300622 foreach (array_keys($_SESSION['__ci_f']) as $key)
Andrey Andreevecc260e2014-01-24 14:20:13 +0200623 {
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300624 $flashdata[$key] = $_SESSION[$key];
Andrey Andreevecc260e2014-01-24 14:20:13 +0200625 }
626 }
627
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300628 return $flashdata;
Darren Hillc4e266b2011-08-30 15:40:27 -0400629 }
630
Andrey Andreev9ffcee62012-09-05 16:25:16 +0300631 // ------------------------------------------------------------------------
632
Darren Hillc4e266b2011-08-30 15:40:27 -0400633 /**
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300634 * Set flashdata
Darren Hillc4e266b2011-08-30 15:40:27 -0400635 *
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300636 * Legacy CI_Session compatibiliy method
637 *
638 * @param mixed $data Session data key or an associative array
639 * @param mixed $value Value to store
Darren Hill5073a372011-08-31 13:54:19 -0400640 * @return void
Darren Hillc4e266b2011-08-30 15:40:27 -0400641 */
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300642 public function set_flashdata($data, $value = NULL)
Darren Hillc4e266b2011-08-30 15:40:27 -0400643 {
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300644 $this->set_userdata($data, $value);
645 $this->mark_as_flash($data);
Darren Hillc4e266b2011-08-30 15:40:27 -0400646 }
647
Andrey Andreev9ffcee62012-09-05 16:25:16 +0300648 // ------------------------------------------------------------------------
649
Darren Hillc4e266b2011-08-30 15:40:27 -0400650 /**
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300651 * Keep flashdata
Darren Hillc4e266b2011-08-30 15:40:27 -0400652 *
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300653 * Legacy CI_Session compatibility method
654 *
655 * @param mixed $key Session data key(s)
Darren Hill5073a372011-08-31 13:54:19 -0400656 * @return void
Darren Hillc4e266b2011-08-30 15:40:27 -0400657 */
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300658 public function keep_flashdata($key)
Darren Hillc4e266b2011-08-30 15:40:27 -0400659 {
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300660 $this->mark_as_flash($key);
Darren Hillc4e266b2011-08-30 15:40:27 -0400661 }
662
Andrey Andreev9ffcee62012-09-05 16:25:16 +0300663 // ------------------------------------------------------------------------
664
Darren Hillc4e266b2011-08-30 15:40:27 -0400665 /**
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300666 * Temp data (fetch)
Darren Hillc4e266b2011-08-30 15:40:27 -0400667 *
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300668 * Legacy CI_Session compatibility method
669 *
670 * @param string $key Session data key
671 * @return mixed Session data value or NULL if not found
Darren Hillc4e266b2011-08-30 15:40:27 -0400672 */
Andrey Andreevecc260e2014-01-24 14:20:13 +0200673 public function tempdata($key = NULL)
Darren Hillc4e266b2011-08-30 15:40:27 -0400674 {
Andrey Andreevecc260e2014-01-24 14:20:13 +0200675 if (isset($key))
676 {
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300677 return isset($_SESSION['__ci_t'], $_SESSION['__ci_t'][$key], $_SESSION[$key])
678 ? $_SESSION[$key]
679 : NULL;
Andrey Andreevecc260e2014-01-24 14:20:13 +0200680 }
681
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300682 $tempdata = array();
683
684 if ( ! empty($_SESSION['__ci_t']))
Andrey Andreevecc260e2014-01-24 14:20:13 +0200685 {
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300686 foreach (array_keys($_SESSION['__ci_t']) as $key)
Andrey Andreevecc260e2014-01-24 14:20:13 +0200687 {
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300688 $tempdata[$key] = $_SESSION[$key];
Andrey Andreevecc260e2014-01-24 14:20:13 +0200689 }
690 }
691
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300692 return $tempdata;
Darren Hillc4e266b2011-08-30 15:40:27 -0400693 }
694
Andrey Andreev9ffcee62012-09-05 16:25:16 +0300695 // ------------------------------------------------------------------------
696
Darren Hillc4e266b2011-08-30 15:40:27 -0400697 /**
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300698 * Set tempdata
Darren Hillc4e266b2011-08-30 15:40:27 -0400699 *
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300700 * Legacy CI_Session compatibility method
701 *
702 * @param mixed $data Session data key or an associative array of items
703 * @param mixed $value Value to store
704 * @param int $ttl Time-to-live in seconds
Darren Hillc4e266b2011-08-30 15:40:27 -0400705 * @return void
706 */
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300707 public function set_tempdata($data, $value = NULL, $ttl = 300)
Darren Hillc4e266b2011-08-30 15:40:27 -0400708 {
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300709 $this->set_userdata($data, $value);
710 $this->mark_as_temp($data, $ttl);
Darren Hillc4e266b2011-08-30 15:40:27 -0400711 }
712
Andrey Andreev9ffcee62012-09-05 16:25:16 +0300713 // ------------------------------------------------------------------------
714
Darren Hillc4e266b2011-08-30 15:40:27 -0400715 /**
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300716 * Unset tempdata
Darren Hillc4e266b2011-08-30 15:40:27 -0400717 *
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300718 * Legacy CI_Session compatibility method
719 *
720 * @param mixed $data Session data key(s)
Darren Hillc4e266b2011-08-30 15:40:27 -0400721 * @return void
722 */
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300723 public function unset_tempdata($key)
Darren Hillc4e266b2011-08-30 15:40:27 -0400724 {
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300725 $this->unmark_temp($key);
Darren Hillc4e266b2011-08-30 15:40:27 -0400726 }
727
Andrey Andreev9ffcee62012-09-05 16:25:16 +0300728}
Darren Hillc4e266b2011-08-30 15:40:27 -0400729
730/* End of file Session.php */
Andrey Andreev9ffcee62012-09-05 16:25:16 +0300731/* Location: ./system/libraries/Session/Session.php */