Subversion-Projekte lars-tiefland.ci

Revision

Revision 1257 | Zur aktuellen Revision | Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
68 lars 1
<?php
2
/**
3
 * CodeIgniter
4
 *
5
 * An open source application development framework for PHP
6
 *
7
 * This content is released under the MIT License (MIT)
8
 *
9
 * Copyright (c) 2014 - 2016, British Columbia Institute of Technology
10
 *
11
 * Permission is hereby granted, free of charge, to any person obtaining a copy
12
 * of this software and associated documentation files (the "Software"), to deal
13
 * in the Software without restriction, including without limitation the rights
14
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15
 * copies of the Software, and to permit persons to whom the Software is
16
 * furnished to do so, subject to the following conditions:
17
 *
18
 * The above copyright notice and this permission notice shall be included in
19
 * all copies or substantial portions of the Software.
20
 *
21
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
27
 * THE SOFTWARE.
28
 *
29
 * @package	CodeIgniter
30
 * @author	EllisLab Dev Team
31
 * @copyright	Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
32
 * @copyright	Copyright (c) 2014 - 2016, British Columbia Institute of Technology (http://bcit.ca/)
33
 * @license	http://opensource.org/licenses/MIT	MIT License
34
 * @link	https://codeigniter.com
35
 * @since	Version 2.0.0
36
 * @filesource
37
 */
38
defined('BASEPATH') OR exit('No direct script access allowed');
39
 
40
/**
41
 * CodeIgniter Session Class
42
 *
43
 * @package		CodeIgniter
44
 * @subpackage	Libraries
45
 * @category	Sessions
46
 * @author		Andrey Andreev
47
 * @link		https://codeigniter.com/user_guide/libraries/sessions.html
48
 */
49
class CI_Session {
50
 
51
	/**
52
	 * Userdata array
53
	 *
54
	 * Just a reference to $_SESSION, for BC purposes.
55
	 */
56
	public $userdata;
57
 
58
	protected $_driver = 'files';
59
	protected $_config;
60
 
61
	// ------------------------------------------------------------------------
62
 
63
	/**
64
	 * Class constructor
65
	 *
66
	 * @param	array	$params	Configuration parameters
67
	 * @return	void
68
	 */
69
	public function __construct(array $params = array())
70
	{
71
		// No sessions under CLI
72
		if (is_cli())
73
		{
74
			log_message('debug', 'Session: Initialization under CLI aborted.');
75
			return;
76
		}
77
		elseif ((bool) ini_get('session.auto_start'))
78
		{
79
			log_message('error', 'Session: session.auto_start is enabled in php.ini. Aborting.');
80
			return;
81
		}
82
		elseif ( ! empty($params['driver']))
83
		{
84
			$this->_driver = $params['driver'];
85
			unset($params['driver']);
86
		}
87
		elseif ($driver = config_item('sess_driver'))
88
		{
89
			$this->_driver = $driver;
90
		}
91
		// Note: BC workaround
92
		elseif (config_item('sess_use_database'))
93
		{
94
			log_message('debug', 'Session: "sess_driver" is empty; using BC fallback to "sess_use_database".');
95
			$this->_driver = 'database';
96
		}
97
 
98
		$class = $this->_ci_load_classes($this->_driver);
99
 
100
		// Configuration ...
101
		$this->_configure($params);
102
 
103
		$class = new $class($this->_config);
104
		if ($class instanceof SessionHandlerInterface)
105
		{
106
			if (is_php('5.4'))
107
			{
108
				session_set_save_handler($class, TRUE);
109
			}
110
			else
111
			{
112
				session_set_save_handler(
113
					array($class, 'open'),
114
					array($class, 'close'),
115
					array($class, 'read'),
116
					array($class, 'write'),
117
					array($class, 'destroy'),
118
					array($class, 'gc')
119
				);
120
 
121
				register_shutdown_function('session_write_close');
122
			}
123
		}
124
		else
125
		{
126
			log_message('error', "Session: Driver '".$this->_driver."' doesn't implement SessionHandlerInterface. Aborting.");
127
			return;
128
		}
129
 
130
		// Sanitize the cookie, because apparently PHP doesn't do that for userspace handlers
131
		if (isset($_COOKIE[$this->_config['cookie_name']])
132
			&& (
133
				! is_string($_COOKIE[$this->_config['cookie_name']])
134
				OR ! preg_match('/^[0-9a-f]{40}$/', $_COOKIE[$this->_config['cookie_name']])
135
			)
136
		)
137
		{
138
			unset($_COOKIE[$this->_config['cookie_name']]);
139
		}
140
 
141
		session_start();
142
 
143
		// Is session ID auto-regeneration configured? (ignoring ajax requests)
144
		if ((empty($_SERVER['HTTP_X_REQUESTED_WITH']) OR strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) !== 'xmlhttprequest')
145
			&& ($regenerate_time = config_item('sess_time_to_update')) > 0
146
		)
147
		{
148
			if ( ! isset($_SESSION['__ci_last_regenerate']))
149
			{
150
				$_SESSION['__ci_last_regenerate'] = time();
151
			}
152
			elseif ($_SESSION['__ci_last_regenerate'] < (time() - $regenerate_time))
153
			{
154
				$this->sess_regenerate((bool) config_item('sess_regenerate_destroy'));
155
			}
156
		}
157
		// Another work-around ... PHP doesn't seem to send the session cookie
158
		// unless it is being currently created or regenerated
159
		elseif (isset($_COOKIE[$this->_config['cookie_name']]) && $_COOKIE[$this->_config['cookie_name']] === session_id())
160
		{
161
			setcookie(
162
				$this->_config['cookie_name'],
163
				session_id(),
164
				(empty($this->_config['cookie_lifetime']) ? 0 : time() + $this->_config['cookie_lifetime']),
165
				$this->_config['cookie_path'],
166
				$this->_config['cookie_domain'],
167
				$this->_config['cookie_secure'],
168
				TRUE
169
			);
170
		}
171
 
172
		$this->_ci_init_vars();
173
 
174
		log_message('info', "Session: Class initialized using '".$this->_driver."' driver.");
175
	}
176
 
177
	// ------------------------------------------------------------------------
178
 
179
	/**
180
	 * CI Load Classes
181
	 *
182
	 * An internal method to load all possible dependency and extension
183
	 * classes. It kind of emulates the CI_Driver library, but is
184
	 * self-sufficient.
185
	 *
186
	 * @param	string	$driver	Driver name
187
	 * @return	string	Driver class name
188
	 */
189
	protected function _ci_load_classes($driver)
190
	{
191
		// PHP 5.4 compatibility
192
		interface_exists('SessionHandlerInterface', FALSE) OR require_once(BASEPATH.'libraries/Session/SessionHandlerInterface.php');
193
 
194
		$prefix = config_item('subclass_prefix');
195
 
196
		if ( ! class_exists('CI_Session_driver', FALSE))
197
		{
198
			require_once(
199
				file_exists(APPPATH.'libraries/Session/Session_driver.php')
200
					? APPPATH.'libraries/Session/Session_driver.php'
201
					: BASEPATH.'libraries/Session/Session_driver.php'
202
			);
203
 
204
			if (file_exists($file_path = APPPATH.'libraries/Session/'.$prefix.'Session_driver.php'))
205
			{
206
				require_once($file_path);
207
			}
208
		}
209
 
210
		$class = 'Session_'.$driver.'_driver';
211
 
212
		// Allow custom drivers without the CI_ or MY_ prefix
213
		if ( ! class_exists($class, FALSE) && file_exists($file_path = APPPATH.'libraries/Session/drivers/'.$class.'.php'))
214
		{
215
			require_once($file_path);
216
			if (class_exists($class, FALSE))
217
			{
218
				return $class;
219
			}
220
		}
221
 
222
		if ( ! class_exists('CI_'.$class, FALSE))
223
		{
224
			if (file_exists($file_path = APPPATH.'libraries/Session/drivers/'.$class.'.php') OR file_exists($file_path = BASEPATH.'libraries/Session/drivers/'.$class.'.php'))
225
			{
226
				require_once($file_path);
227
			}
228
 
229
			if ( ! class_exists('CI_'.$class, FALSE) && ! class_exists($class, FALSE))
230
			{
231
				throw new UnexpectedValueException("Session: Configured driver '".$driver."' was not found. Aborting.");
232
			}
233
		}
234
 
235
		if ( ! class_exists($prefix.$class, FALSE) && file_exists($file_path = APPPATH.'libraries/Session/drivers/'.$prefix.$class.'.php'))
236
		{
237
			require_once($file_path);
238
			if (class_exists($prefix.$class, FALSE))
239
			{
240
				return $prefix.$class;
241
			}
242
			else
243
			{
244
				log_message('debug', 'Session: '.$prefix.$class.".php found but it doesn't declare class ".$prefix.$class.'.');
245
			}
246
		}
247
 
248
		return 'CI_'.$class;
249
	}
250
 
251
	// ------------------------------------------------------------------------
252
 
253
	/**
254
	 * Configuration
255
	 *
256
	 * Handle input parameters and configuration defaults
257
	 *
258
	 * @param	array	&$params	Input parameters
259
	 * @return	void
260
	 */
261
	protected function _configure(&$params)
262
	{
263
		$expiration = config_item('sess_expiration');
264
 
265
		if (isset($params['cookie_lifetime']))
266
		{
267
			$params['cookie_lifetime'] = (int) $params['cookie_lifetime'];
268
		}
269
		else
270
		{
271
			$params['cookie_lifetime'] = ( ! isset($expiration) && config_item('sess_expire_on_close'))
272
				? 0 : (int) $expiration;
273
		}
274
 
275
		isset($params['cookie_name']) OR $params['cookie_name'] = config_item('sess_cookie_name');
276
		if (empty($params['cookie_name']))
277
		{
278
			$params['cookie_name'] = ini_get('session.name');
279
		}
280
		else
281
		{
282
			ini_set('session.name', $params['cookie_name']);
283
		}
284
 
285
		isset($params['cookie_path']) OR $params['cookie_path'] = config_item('cookie_path');
286
		isset($params['cookie_domain']) OR $params['cookie_domain'] = config_item('cookie_domain');
287
		isset($params['cookie_secure']) OR $params['cookie_secure'] = (bool) config_item('cookie_secure');
288
 
289
		session_set_cookie_params(
290
			$params['cookie_lifetime'],
291
			$params['cookie_path'],
292
			$params['cookie_domain'],
293
			$params['cookie_secure'],
294
			TRUE // HttpOnly; Yes, this is intentional and not configurable for security reasons
295
		);
296
 
297
		if (empty($expiration))
298
		{
299
			$params['expiration'] = (int) ini_get('session.gc_maxlifetime');
300
		}
301
		else
302
		{
303
			$params['expiration'] = (int) $expiration;
304
			ini_set('session.gc_maxlifetime', $expiration);
305
		}
306
 
307
		$params['match_ip'] = (bool) (isset($params['match_ip']) ? $params['match_ip'] : config_item('sess_match_ip'));
308
 
309
		isset($params['save_path']) OR $params['save_path'] = config_item('sess_save_path');
310
 
311
		$this->_config = $params;
312
 
313
		// Security is king
314
		ini_set('session.use_trans_sid', 0);
315
		ini_set('session.use_strict_mode', 1);
316
		ini_set('session.use_cookies', 1);
317
		ini_set('session.use_only_cookies', 1);
318
		ini_set('session.hash_function', 1);
319
		ini_set('session.hash_bits_per_character', 4);
320
	}
321
 
322
	// ------------------------------------------------------------------------
323
 
324
	/**
325
	 * Handle temporary variables
326
	 *
327
	 * Clears old "flash" data, marks the new one for deletion and handles
328
	 * "temp" data deletion.
329
	 *
330
	 * @return	void
331
	 */
332
	protected function _ci_init_vars()
333
	{
334
		if ( ! empty($_SESSION['__ci_vars']))
335
		{
336
			$current_time = time();
337
 
338
			foreach ($_SESSION['__ci_vars'] as $key => &$value)
339
			{
340
				if ($value === 'new')
341
				{
342
					$_SESSION['__ci_vars'][$key] = 'old';
343
				}
344
				// Hacky, but 'old' will (implicitly) always be less than time() ;)
345
				// DO NOT move this above the 'new' check!
346
				elseif ($value < $current_time)
347
				{
348
					unset($_SESSION[$key], $_SESSION['__ci_vars'][$key]);
349
				}
350
			}
351
 
352
			if (empty($_SESSION['__ci_vars']))
353
			{
354
				unset($_SESSION['__ci_vars']);
355
			}
356
		}
357
 
358
		$this->userdata =& $_SESSION;
359
	}
360
 
361
	// ------------------------------------------------------------------------
362
 
363
	/**
364
	 * Mark as flash
365
	 *
366
	 * @param	mixed	$key	Session data key(s)
367
	 * @return	bool
368
	 */
369
	public function mark_as_flash($key)
370
	{
371
		if (is_array($key))
372
		{
373
			for ($i = 0, $c = count($key); $i < $c; $i++)
374
			{
375
				if ( ! isset($_SESSION[$key[$i]]))
376
				{
377
					return FALSE;
378
				}
379
			}
380
 
381
			$new = array_fill_keys($key, 'new');
382
 
383
			$_SESSION['__ci_vars'] = isset($_SESSION['__ci_vars'])
384
				? array_merge($_SESSION['__ci_vars'], $new)
385
				: $new;
386
 
387
			return TRUE;
388
		}
389
 
390
		if ( ! isset($_SESSION[$key]))
391
		{
392
			return FALSE;
393
		}
394
 
395
		$_SESSION['__ci_vars'][$key] = 'new';
396
		return TRUE;
397
	}
398
 
399
	// ------------------------------------------------------------------------
400
 
401
	/**
402
	 * Get flash keys
403
	 *
404
	 * @return	array
405
	 */
406
	public function get_flash_keys()
407
	{
408
		if ( ! isset($_SESSION['__ci_vars']))
409
		{
410
			return array();
411
		}
412
 
413
		$keys = array();
414
		foreach (array_keys($_SESSION['__ci_vars']) as $key)
415
		{
416
			is_int($_SESSION['__ci_vars'][$key]) OR $keys[] = $key;
417
		}
418
 
419
		return $keys;
420
	}
421
 
422
	// ------------------------------------------------------------------------
423
 
424
	/**
425
	 * Unmark flash
426
	 *
427
	 * @param	mixed	$key	Session data key(s)
428
	 * @return	void
429
	 */
430
	public function unmark_flash($key)
431
	{
432
		if (empty($_SESSION['__ci_vars']))
433
		{
434
			return;
435
		}
436
 
437
		is_array($key) OR $key = array($key);
438
 
439
		foreach ($key as $k)
440
		{
441
			if (isset($_SESSION['__ci_vars'][$k]) && ! is_int($_SESSION['__ci_vars'][$k]))
442
			{
443
				unset($_SESSION['__ci_vars'][$k]);
444
			}
445
		}
446
 
447
		if (empty($_SESSION['__ci_vars']))
448
		{
449
			unset($_SESSION['__ci_vars']);
450
		}
451
	}
452
 
453
	// ------------------------------------------------------------------------
454
 
455
	/**
456
	 * Mark as temp
457
	 *
458
	 * @param	mixed	$key	Session data key(s)
459
	 * @param	int	$ttl	Time-to-live in seconds
460
	 * @return	bool
461
	 */
462
	public function mark_as_temp($key, $ttl = 300)
463
	{
464
		$ttl += time();
465
 
466
		if (is_array($key))
467
		{
468
			$temp = array();
469
 
470
			foreach ($key as $k => $v)
471
			{
472
				// Do we have a key => ttl pair, or just a key?
473
				if (is_int($k))
474
				{
475
					$k = $v;
476
					$v = $ttl;
477
				}
478
				else
479
				{
480
					$v += time();
481
				}
482
 
483
				if ( ! isset($_SESSION[$k]))
484
				{
485
					return FALSE;
486
				}
487
 
488
				$temp[$k] = $v;
489
			}
490
 
491
			$_SESSION['__ci_vars'] = isset($_SESSION['__ci_vars'])
492
				? array_merge($_SESSION['__ci_vars'], $temp)
493
				: $temp;
494
 
495
			return TRUE;
496
		}
497
 
498
		if ( ! isset($_SESSION[$key]))
499
		{
500
			return FALSE;
501
		}
502
 
503
		$_SESSION['__ci_vars'][$key] = $ttl;
504
		return TRUE;
505
	}
506
 
507
	// ------------------------------------------------------------------------
508
 
509
	/**
510
	 * Get temp keys
511
	 *
512
	 * @return	array
513
	 */
514
	public function get_temp_keys()
515
	{
516
		if ( ! isset($_SESSION['__ci_vars']))
517
		{
518
			return array();
519
		}
520
 
521
		$keys = array();
522
		foreach (array_keys($_SESSION['__ci_vars']) as $key)
523
		{
524
			is_int($_SESSION['__ci_vars'][$key]) && $keys[] = $key;
525
		}
526
 
527
		return $keys;
528
	}
529
 
530
	// ------------------------------------------------------------------------
531
 
532
	/**
533
	 * Unmark flash
534
	 *
535
	 * @param	mixed	$key	Session data key(s)
536
	 * @return	void
537
	 */
538
	public function unmark_temp($key)
539
	{
540
		if (empty($_SESSION['__ci_vars']))
541
		{
542
			return;
543
		}
544
 
545
		is_array($key) OR $key = array($key);
546
 
547
		foreach ($key as $k)
548
		{
549
			if (isset($_SESSION['__ci_vars'][$k]) && is_int($_SESSION['__ci_vars'][$k]))
550
			{
551
				unset($_SESSION['__ci_vars'][$k]);
552
			}
553
		}
554
 
555
		if (empty($_SESSION['__ci_vars']))
556
		{
557
			unset($_SESSION['__ci_vars']);
558
		}
559
	}
560
 
561
	// ------------------------------------------------------------------------
562
 
563
	/**
564
	 * __get()
565
	 *
566
	 * @param	string	$key	'session_id' or a session data key
567
	 * @return	mixed
568
	 */
569
	public function __get($key)
570
	{
571
		// Note: Keep this order the same, just in case somebody wants to
572
		//       use 'session_id' as a session data key, for whatever reason
573
		if (isset($_SESSION[$key]))
574
		{
575
			return $_SESSION[$key];
576
		}
577
		elseif ($key === 'session_id')
578
		{
579
			return session_id();
580
		}
581
 
582
		return NULL;
583
	}
584
 
585
	// ------------------------------------------------------------------------
586
 
587
	/**
588
	 * __isset()
589
	 *
590
	 * @param	string	$key	'session_id' or a session data key
591
	 * @return	bool
592
	 */
593
	public function __isset($key)
594
	{
595
		if ($key === 'session_id')
596
		{
597
			return (session_status() === PHP_SESSION_ACTIVE);
598
		}
599
 
600
		return isset($_SESSION[$key]);
601
	}
602
 
603
	// ------------------------------------------------------------------------
604
 
605
	/**
606
	 * __set()
607
	 *
608
	 * @param	string	$key	Session data key
609
	 * @param	mixed	$value	Session data value
610
	 * @return	void
611
	 */
612
	public function __set($key, $value)
613
	{
614
		$_SESSION[$key] = $value;
615
	}
616
 
617
	// ------------------------------------------------------------------------
618
 
619
	/**
620
	 * Session destroy
621
	 *
622
	 * Legacy CI_Session compatibility method
623
	 *
624
	 * @return	void
625
	 */
626
	public function sess_destroy()
627
	{
628
		session_destroy();
629
	}
630
 
631
	// ------------------------------------------------------------------------
632
 
633
	/**
634
	 * Session regenerate
635
	 *
636
	 * Legacy CI_Session compatibility method
637
	 *
638
	 * @param	bool	$destroy	Destroy old session data flag
639
	 * @return	void
640
	 */
641
	public function sess_regenerate($destroy = FALSE)
642
	{
643
		$_SESSION['__ci_last_regenerate'] = time();
644
		session_regenerate_id($destroy);
645
	}
646
 
647
	// ------------------------------------------------------------------------
648
 
649
	/**
650
	 * Get userdata reference
651
	 *
652
	 * Legacy CI_Session compatibility method
653
	 *
654
	 * @returns	array
655
	 */
656
	public function &get_userdata()
657
	{
658
		return $_SESSION;
659
	}
660
 
661
	// ------------------------------------------------------------------------
662
 
663
	/**
664
	 * Userdata (fetch)
665
	 *
666
	 * Legacy CI_Session compatibility method
667
	 *
668
	 * @param	string	$key	Session data key
669
	 * @return	mixed	Session data value or NULL if not found
670
	 */
671
	public function userdata($key = NULL)
672
	{
673
		if (isset($key))
674
		{
675
			return isset($_SESSION[$key]) ? $_SESSION[$key] : NULL;
676
		}
677
		elseif (empty($_SESSION))
678
		{
679
			return array();
680
		}
681
 
682
		$userdata = array();
683
		$_exclude = array_merge(
684
			array('__ci_vars'),
685
			$this->get_flash_keys(),
686
			$this->get_temp_keys()
687
		);
688
 
689
		foreach (array_keys($_SESSION) as $key)
690
		{
691
			if ( ! in_array($key, $_exclude, TRUE))
692
			{
693
				$userdata[$key] = $_SESSION[$key];
694
			}
695
		}
696
 
697
		return $userdata;
698
	}
699
 
700
	// ------------------------------------------------------------------------
701
 
702
	/**
703
	 * Set userdata
704
	 *
705
	 * Legacy CI_Session compatibility method
706
	 *
707
	 * @param	mixed	$data	Session data key or an associative array
708
	 * @param	mixed	$value	Value to store
709
	 * @return	void
710
	 */
711
	public function set_userdata($data, $value = NULL)
712
	{
713
		if (is_array($data))
714
		{
715
			foreach ($data as $key => &$value)
716
			{
717
				$_SESSION[$key] = $value;
718
			}
719
 
720
			return;
721
		}
722
 
723
		$_SESSION[$data] = $value;
724
	}
725
 
726
	// ------------------------------------------------------------------------
727
 
728
	/**
729
	 * Unset userdata
730
	 *
731
	 * Legacy CI_Session compatibility method
732
	 *
733
	 * @param	mixed	$key	Session data key(s)
734
	 * @return	void
735
	 */
736
	public function unset_userdata($key)
737
	{
738
		if (is_array($key))
739
		{
740
			foreach ($key as $k)
741
			{
742
				unset($_SESSION[$k]);
743
			}
744
 
745
			return;
746
		}
747
 
748
		unset($_SESSION[$key]);
749
	}
750
 
751
	// ------------------------------------------------------------------------
752
 
753
	/**
754
	 * All userdata (fetch)
755
	 *
756
	 * Legacy CI_Session compatibility method
757
	 *
758
	 * @return	array	$_SESSION, excluding flash data items
759
	 */
760
	public function all_userdata()
761
	{
762
		return $this->userdata();
763
	}
764
 
765
	// ------------------------------------------------------------------------
766
 
767
	/**
768
	 * Has userdata
769
	 *
770
	 * Legacy CI_Session compatibility method
771
	 *
772
	 * @param	string	$key	Session data key
773
	 * @return	bool
774
	 */
775
	public function has_userdata($key)
776
	{
777
		return isset($_SESSION[$key]);
778
	}
779
 
780
	// ------------------------------------------------------------------------
781
 
782
	/**
783
	 * Flashdata (fetch)
784
	 *
785
	 * Legacy CI_Session compatibility method
786
	 *
787
	 * @param	string	$key	Session data key
788
	 * @return	mixed	Session data value or NULL if not found
789
	 */
790
	public function flashdata($key = NULL)
791
	{
792
		if (isset($key))
793
		{
794
			return (isset($_SESSION['__ci_vars'], $_SESSION['__ci_vars'][$key], $_SESSION[$key]) && ! is_int($_SESSION['__ci_vars'][$key]))
795
				? $_SESSION[$key]
796
				: NULL;
797
		}
798
 
799
		$flashdata = array();
800
 
801
		if ( ! empty($_SESSION['__ci_vars']))
802
		{
803
			foreach ($_SESSION['__ci_vars'] as $key => &$value)
804
			{
805
				is_int($value) OR $flashdata[$key] = $_SESSION[$key];
806
			}
807
		}
808
 
809
		return $flashdata;
810
	}
811
 
812
	// ------------------------------------------------------------------------
813
 
814
	/**
815
	 * Set flashdata
816
	 *
817
	 * Legacy CI_Session compatibility method
818
	 *
819
	 * @param	mixed	$data	Session data key or an associative array
820
	 * @param	mixed	$value	Value to store
821
	 * @return	void
822
	 */
823
	public function set_flashdata($data, $value = NULL)
824
	{
825
		$this->set_userdata($data, $value);
826
		$this->mark_as_flash(is_array($data) ? array_keys($data) : $data);
827
	}
828
 
829
	// ------------------------------------------------------------------------
830
 
831
	/**
832
	 * Keep flashdata
833
	 *
834
	 * Legacy CI_Session compatibility method
835
	 *
836
	 * @param	mixed	$key	Session data key(s)
837
	 * @return	void
838
	 */
839
	public function keep_flashdata($key)
840
	{
841
		$this->mark_as_flash($key);
842
	}
843
 
844
	// ------------------------------------------------------------------------
845
 
846
	/**
847
	 * Temp data (fetch)
848
	 *
849
	 * Legacy CI_Session compatibility method
850
	 *
851
	 * @param	string	$key	Session data key
852
	 * @return	mixed	Session data value or NULL if not found
853
	 */
854
	public function tempdata($key = NULL)
855
	{
856
		if (isset($key))
857
		{
858
			return (isset($_SESSION['__ci_vars'], $_SESSION['__ci_vars'][$key], $_SESSION[$key]) && is_int($_SESSION['__ci_vars'][$key]))
859
				? $_SESSION[$key]
860
				: NULL;
861
		}
862
 
863
		$tempdata = array();
864
 
865
		if ( ! empty($_SESSION['__ci_vars']))
866
		{
867
			foreach ($_SESSION['__ci_vars'] as $key => &$value)
868
			{
869
				is_int($value) && $tempdata[$key] = $_SESSION[$key];
870
			}
871
		}
872
 
873
		return $tempdata;
874
	}
875
 
876
	// ------------------------------------------------------------------------
877
 
878
	/**
879
	 * Set tempdata
880
	 *
881
	 * Legacy CI_Session compatibility method
882
	 *
883
	 * @param	mixed	$data	Session data key or an associative array of items
884
	 * @param	mixed	$value	Value to store
885
	 * @param	int	$ttl	Time-to-live in seconds
886
	 * @return	void
887
	 */
888
	public function set_tempdata($data, $value = NULL, $ttl = 300)
889
	{
890
		$this->set_userdata($data, $value);
891
		$this->mark_as_temp(is_array($data) ? array_keys($data) : $data, $ttl);
892
	}
893
 
894
	// ------------------------------------------------------------------------
895
 
896
	/**
897
	 * Unset tempdata
898
	 *
899
	 * Legacy CI_Session compatibility method
900
	 *
901
	 * @param	mixed	$data	Session data key(s)
902
	 * @return	void
903
	 */
904
	public function unset_tempdata($key)
905
	{
906
		$this->unmark_temp($key);
907
	}
908
 
909
}