PageRenderTime 45ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/system/libraries/Session/Session.php

https://gitlab.com/betanurlaila/UI_onlineshop
PHP | 908 lines | 809 code | 23 blank | 76 comment | 22 complexity | f1ade41e94d962977e4472e873750ecf MD5 | raw file
  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. * CodeIgniter Session Class
  41. *
  42. * @package CodeIgniter
  43. * @subpackage Libraries
  44. * @category Sessions
  45. * @author Andrey Andreev
  46. * @link https://codeigniter.com/user_guide/libraries/sessions.html
  47. */
  48. class CI_Session {
  49. /**
  50. * Userdata array
  51. *
  52. * Just a reference to $_SESSION, for BC purposes.
  53. */
  54. public $userdata;
  55. protected $_driver = 'files';
  56. protected $_config;
  57. // ------------------------------------------------------------------------
  58. /**
  59. * Class constructor
  60. *
  61. * @param array $params Configuration parameters
  62. * @return void
  63. */
  64. public function __construct(array $params = array())
  65. {
  66. // No sessions under CLI
  67. if (is_cli())
  68. {
  69. log_message('debug', 'Session: Initialization under CLI aborted.');
  70. return;
  71. }
  72. elseif ((bool) ini_get('session.auto_start'))
  73. {
  74. log_message('error', 'Session: session.auto_start is enabled in php.ini. Aborting.');
  75. return;
  76. }
  77. elseif ( ! empty($params['driver']))
  78. {
  79. $this->_driver = $params['driver'];
  80. unset($params['driver']);
  81. }
  82. elseif ($driver = config_item('sess_driver'))
  83. {
  84. $this->_driver = $driver;
  85. }
  86. // Note: BC workaround
  87. elseif (config_item('sess_use_database'))
  88. {
  89. $this->_driver = 'database';
  90. }
  91. $class = $this->_ci_load_classes($this->_driver);
  92. // Configuration ...
  93. $this->_configure($params);
  94. $class = new $class($this->_config);
  95. if ($class instanceof SessionHandlerInterface)
  96. {
  97. if (is_php('5.4'))
  98. {
  99. session_set_save_handler($class, TRUE);
  100. }
  101. else
  102. {
  103. session_set_save_handler(
  104. array($class, 'open'),
  105. array($class, 'close'),
  106. array($class, 'read'),
  107. array($class, 'write'),
  108. array($class, 'destroy'),
  109. array($class, 'gc')
  110. );
  111. register_shutdown_function('session_write_close');
  112. }
  113. }
  114. else
  115. {
  116. log_message('error', "Session: Driver '".$this->_driver."' doesn't implement SessionHandlerInterface. Aborting.");
  117. return;
  118. }
  119. // Sanitize the cookie, because apparently PHP doesn't do that for userspace handlers
  120. if (isset($_COOKIE[$this->_config['cookie_name']])
  121. && (
  122. ! is_string($_COOKIE[$this->_config['cookie_name']])
  123. OR ! preg_match('/^[0-9a-f]{40}$/', $_COOKIE[$this->_config['cookie_name']])
  124. )
  125. )
  126. {
  127. unset($_COOKIE[$this->_config['cookie_name']]);
  128. }
  129. session_start();
  130. // Is session ID auto-regeneration configured? (ignoring ajax requests)
  131. if ((empty($_SERVER['HTTP_X_REQUESTED_WITH']) OR strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) !== 'xmlhttprequest')
  132. && ($regenerate_time = config_item('sess_time_to_update')) > 0
  133. )
  134. {
  135. if ( ! isset($_SESSION['__ci_last_regenerate']))
  136. {
  137. $_SESSION['__ci_last_regenerate'] = time();
  138. }
  139. elseif ($_SESSION['__ci_last_regenerate'] < (time() - $regenerate_time))
  140. {
  141. $this->sess_regenerate((bool) config_item('sess_regenerate_destroy'));
  142. }
  143. }
  144. // Another work-around ... PHP doesn't seem to send the session cookie
  145. // unless it is being currently created or regenerated
  146. elseif (isset($_COOKIE[$this->_config['cookie_name']]) && $_COOKIE[$this->_config['cookie_name']] === session_id())
  147. {
  148. setcookie(
  149. $this->_config['cookie_name'],
  150. session_id(),
  151. (empty($this->_config['cookie_lifetime']) ? 0 : time() + $this->_config['cookie_lifetime']),
  152. $this->_config['cookie_path'],
  153. $this->_config['cookie_domain'],
  154. $this->_config['cookie_secure'],
  155. TRUE
  156. );
  157. }
  158. $this->_ci_init_vars();
  159. log_message('info', "Session: Class initialized using '".$this->_driver."' driver.");
  160. }
  161. // ------------------------------------------------------------------------
  162. /**
  163. * CI Load Classes
  164. *
  165. * An internal method to load all possible dependency and extension
  166. * classes. It kind of emulates the CI_Driver library, but is
  167. * self-sufficient.
  168. *
  169. * @param string $driver Driver name
  170. * @return string Driver class name
  171. */
  172. protected function _ci_load_classes($driver)
  173. {
  174. // PHP 5.4 compatibility
  175. interface_exists('SessionHandlerInterface', FALSE) OR require_once(BASEPATH.'libraries/Session/SessionHandlerInterface.php');
  176. $prefix = config_item('subclass_prefix');
  177. if ( ! class_exists('CI_Session_driver', FALSE))
  178. {
  179. require_once(
  180. file_exists(APPPATH.'libraries/Session/Session_driver.php')
  181. ? APPPATH.'libraries/Session/Session_driver.php'
  182. : BASEPATH.'libraries/Session/Session_driver.php'
  183. );
  184. if (file_exists($file_path = APPPATH.'libraries/Session/'.$prefix.'Session_driver.php'))
  185. {
  186. require_once($file_path);
  187. }
  188. }
  189. $class = 'Session_'.$driver.'_driver';
  190. // Allow custom drivers without the CI_ or MY_ prefix
  191. if ( ! class_exists($class, FALSE) && file_exists($file_path = APPPATH.'libraries/Session/drivers/'.$class.'.php'))
  192. {
  193. require_once($file_path);
  194. if (class_exists($class, FALSE))
  195. {
  196. return $class;
  197. }
  198. }
  199. if ( ! class_exists('CI_'.$class, FALSE))
  200. {
  201. if (file_exists($file_path = APPPATH.'libraries/Session/drivers/'.$class.'.php') OR file_exists($file_path = BASEPATH.'libraries/Session/drivers/'.$class.'.php'))
  202. {
  203. require_once($file_path);
  204. }
  205. if ( ! class_exists('CI_'.$class, FALSE) && ! class_exists($class, FALSE))
  206. {
  207. throw new UnexpectedValueException("Session: Configured driver '".$driver."' was not found. Aborting.");
  208. }
  209. }
  210. if ( ! class_exists($prefix.$class, FALSE) && file_exists($file_path = APPPATH.'libraries/Session/drivers/'.$prefix.$class.'.php'))
  211. {
  212. require_once($file_path);
  213. if (class_exists($prefix.$class, FALSE))
  214. {
  215. return $prefix.$class;
  216. }
  217. else
  218. {
  219. log_message('debug', 'Session: '.$prefix.$class.".php found but it doesn't declare class ".$prefix.$class.'.');
  220. }
  221. }
  222. return 'CI_'.$class;
  223. }
  224. // ------------------------------------------------------------------------
  225. /**
  226. * Configuration
  227. *
  228. * Handle input parameters and configuration defaults
  229. *
  230. * @param array &$params Input parameters
  231. * @return void
  232. */
  233. protected function _configure(&$params)
  234. {
  235. $expiration = config_item('sess_expiration');
  236. if (isset($params['cookie_lifetime']))
  237. {
  238. $params['cookie_lifetime'] = (int) $params['cookie_lifetime'];
  239. }
  240. else
  241. {
  242. $params['cookie_lifetime'] = ( ! isset($expiration) && config_item('sess_expire_on_close'))
  243. ? 0 : (int) $expiration;
  244. }
  245. isset($params['cookie_name']) OR $params['cookie_name'] = config_item('sess_cookie_name');
  246. if (empty($params['cookie_name']))
  247. {
  248. $params['cookie_name'] = ini_get('session.name');
  249. }
  250. else
  251. {
  252. ini_set('session.name', $params['cookie_name']);
  253. }
  254. isset($params['cookie_path']) OR $params['cookie_path'] = config_item('cookie_path');
  255. isset($params['cookie_domain']) OR $params['cookie_domain'] = config_item('cookie_domain');
  256. isset($params['cookie_secure']) OR $params['cookie_secure'] = (bool) config_item('cookie_secure');
  257. session_set_cookie_params(
  258. $params['cookie_lifetime'],
  259. $params['cookie_path'],
  260. $params['cookie_domain'],
  261. $params['cookie_secure'],
  262. TRUE // HttpOnly; Yes, this is intentional and not configurable for security reasons
  263. );
  264. if (empty($expiration))
  265. {
  266. $params['expiration'] = (int) ini_get('session.gc_maxlifetime');
  267. }
  268. else
  269. {
  270. $params['expiration'] = (int) $expiration;
  271. ini_set('session.gc_maxlifetime', $expiration);
  272. }
  273. $params['match_ip'] = (bool) (isset($params['match_ip']) ? $params['match_ip'] : config_item('sess_match_ip'));
  274. isset($params['save_path']) OR $params['save_path'] = config_item('sess_save_path');
  275. $this->_config = $params;
  276. // Security is king
  277. ini_set('session.use_trans_sid', 0);
  278. ini_set('session.use_strict_mode', 1);
  279. ini_set('session.use_cookies', 1);
  280. ini_set('session.use_only_cookies', 1);
  281. ini_set('session.hash_function', 1);
  282. ini_set('session.hash_bits_per_character', 4);
  283. }
  284. // ------------------------------------------------------------------------
  285. /**
  286. * Handle temporary variables
  287. *
  288. * Clears old "flash" data, marks the new one for deletion and handles
  289. * "temp" data deletion.
  290. *
  291. * @return void
  292. */
  293. protected function _ci_init_vars()
  294. {
  295. if ( ! empty($_SESSION['__ci_vars']))
  296. {
  297. $current_time = time();
  298. foreach ($_SESSION['__ci_vars'] as $key => &$value)
  299. {
  300. if ($value === 'new')
  301. {
  302. $_SESSION['__ci_vars'][$key] = 'old';
  303. }
  304. // Hacky, but 'old' will (implicitly) always be less than time() ;)
  305. // DO NOT move this above the 'new' check!
  306. elseif ($value < $current_time)
  307. {
  308. unset($_SESSION[$key], $_SESSION['__ci_vars'][$key]);
  309. }
  310. }
  311. if (empty($_SESSION['__ci_vars']))
  312. {
  313. unset($_SESSION['__ci_vars']);
  314. }
  315. }
  316. $this->userdata =& $_SESSION;
  317. }
  318. // ------------------------------------------------------------------------
  319. /**
  320. * Mark as flash
  321. *
  322. * @param mixed $key Session data key(s)
  323. * @return bool
  324. */
  325. public function mark_as_flash($key)
  326. {
  327. if (is_array($key))
  328. {
  329. for ($i = 0, $c = count($key); $i < $c; $i++)
  330. {
  331. if ( ! isset($_SESSION[$key[$i]]))
  332. {
  333. return FALSE;
  334. }
  335. }
  336. $new = array_fill_keys($key, 'new');
  337. $_SESSION['__ci_vars'] = isset($_SESSION['__ci_vars'])
  338. ? array_merge($_SESSION['__ci_vars'], $new)
  339. : $new;
  340. return TRUE;
  341. }
  342. if ( ! isset($_SESSION[$key]))
  343. {
  344. return FALSE;
  345. }
  346. $_SESSION['__ci_vars'][$key] = 'new';
  347. return TRUE;
  348. }
  349. // ------------------------------------------------------------------------
  350. /**
  351. * Get flash keys
  352. *
  353. * @return array
  354. */
  355. public function get_flash_keys()
  356. {
  357. if ( ! isset($_SESSION['__ci_vars']))
  358. {
  359. return array();
  360. }
  361. $keys = array();
  362. foreach (array_keys($_SESSION['__ci_vars']) as $key)
  363. {
  364. is_int($_SESSION['__ci_vars'][$key]) OR $keys[] = $key;
  365. }
  366. return $keys;
  367. }
  368. // ------------------------------------------------------------------------
  369. /**
  370. * Unmark flash
  371. *
  372. * @param mixed $key Session data key(s)
  373. * @return void
  374. */
  375. public function unmark_flash($key)
  376. {
  377. if (empty($_SESSION['__ci_vars']))
  378. {
  379. return;
  380. }
  381. is_array($key) OR $key = array($key);
  382. foreach ($key as $k)
  383. {
  384. if (isset($_SESSION['__ci_vars'][$k]) && ! is_int($_SESSION['__ci_vars'][$k]))
  385. {
  386. unset($_SESSION['__ci_vars'][$k]);
  387. }
  388. }
  389. if (empty($_SESSION['__ci_vars']))
  390. {
  391. unset($_SESSION['__ci_vars']);
  392. }
  393. }
  394. // ------------------------------------------------------------------------
  395. /**
  396. * Mark as temp
  397. *
  398. * @param mixed $key Session data key(s)
  399. * @param int $ttl Time-to-live in seconds
  400. * @return bool
  401. */
  402. public function mark_as_temp($key, $ttl = 300)
  403. {
  404. $ttl += time();
  405. if (is_array($key))
  406. {
  407. $temp = array();
  408. foreach ($key as $k => $v)
  409. {
  410. // Do we have a key => ttl pair, or just a key?
  411. if (is_int($k))
  412. {
  413. $k = $v;
  414. $v = $ttl;
  415. }
  416. else
  417. {
  418. $v += time();
  419. }
  420. if ( ! isset($_SESSION[$k]))
  421. {
  422. return FALSE;
  423. }
  424. $temp[$k] = $v;
  425. }
  426. $_SESSION['__ci_vars'] = isset($_SESSION['__ci_vars'])
  427. ? array_merge($_SESSION['__ci_vars'], $temp)
  428. : $temp;
  429. return TRUE;
  430. }
  431. if ( ! isset($_SESSION[$key]))
  432. {
  433. return FALSE;
  434. }
  435. $_SESSION['__ci_vars'][$key] = $ttl;
  436. return TRUE;
  437. }
  438. // ------------------------------------------------------------------------
  439. /**
  440. * Get temp keys
  441. *
  442. * @return array
  443. */
  444. public function get_temp_keys()
  445. {
  446. if ( ! isset($_SESSION['__ci_vars']))
  447. {
  448. return array();
  449. }
  450. $keys = array();
  451. foreach (array_keys($_SESSION['__ci_vars']) as $key)
  452. {
  453. is_int($_SESSION['__ci_vars'][$key]) && $keys[] = $key;
  454. }
  455. return $keys;
  456. }
  457. // ------------------------------------------------------------------------
  458. /**
  459. * Unmark flash
  460. *
  461. * @param mixed $key Session data key(s)
  462. * @return void
  463. */
  464. public function unmark_temp($key)
  465. {
  466. if (empty($_SESSION['__ci_vars']))
  467. {
  468. return;
  469. }
  470. is_array($key) OR $key = array($key);
  471. foreach ($key as $k)
  472. {
  473. if (isset($_SESSION['__ci_vars'][$k]) && is_int($_SESSION['__ci_vars'][$k]))
  474. {
  475. unset($_SESSION['__ci_vars'][$k]);
  476. }
  477. }
  478. if (empty($_SESSION['__ci_vars']))
  479. {
  480. unset($_SESSION['__ci_vars']);
  481. }
  482. }
  483. // ------------------------------------------------------------------------
  484. /**
  485. * __get()
  486. *
  487. * @param string $key 'session_id' or a session data key
  488. * @return mixed
  489. */
  490. public function __get($key)
  491. {
  492. // Note: Keep this order the same, just in case somebody wants to
  493. // use 'session_id' as a session data key, for whatever reason
  494. if (isset($_SESSION[$key]))
  495. {
  496. return $_SESSION[$key];
  497. }
  498. elseif ($key === 'session_id')
  499. {
  500. return session_id();
  501. }
  502. return NULL;
  503. }
  504. // ------------------------------------------------------------------------
  505. /**
  506. * __isset()
  507. *
  508. * @param string $key 'session_id' or a session data key
  509. * @return bool
  510. */
  511. public function __isset($key)
  512. {
  513. if ($key === 'session_id')
  514. {
  515. return (session_status() === PHP_SESSION_ACTIVE);
  516. }
  517. return isset($_SESSION[$key]);
  518. }
  519. // ------------------------------------------------------------------------
  520. /**
  521. * __set()
  522. *
  523. * @param string $key Session data key
  524. * @param mixed $value Session data value
  525. * @return void
  526. */
  527. public function __set($key, $value)
  528. {
  529. $_SESSION[$key] = $value;
  530. }
  531. // ------------------------------------------------------------------------
  532. /**
  533. * Session destroy
  534. *
  535. * Legacy CI_Session compatibility method
  536. *
  537. * @return void
  538. */
  539. public function sess_destroy()
  540. {
  541. session_destroy();
  542. }
  543. // ------------------------------------------------------------------------
  544. /**
  545. * Session regenerate
  546. *
  547. * Legacy CI_Session compatibility method
  548. *
  549. * @param bool $destroy Destroy old session data flag
  550. * @return void
  551. */
  552. public function sess_regenerate($destroy = FALSE)
  553. {
  554. $_SESSION['__ci_last_regenerate'] = time();
  555. session_regenerate_id($destroy);
  556. }
  557. // ------------------------------------------------------------------------
  558. /**
  559. * Get userdata reference
  560. *
  561. * Legacy CI_Session compatibility method
  562. *
  563. * @returns array
  564. */
  565. public function &get_userdata()
  566. {
  567. return $_SESSION;
  568. }
  569. // ------------------------------------------------------------------------
  570. /**
  571. * Userdata (fetch)
  572. *
  573. * Legacy CI_Session compatibility method
  574. *
  575. * @param string $key Session data key
  576. * @return mixed Session data value or NULL if not found
  577. */
  578. public function userdata($key = NULL)
  579. {
  580. if (isset($key))
  581. {
  582. return isset($_SESSION[$key]) ? $_SESSION[$key] : NULL;
  583. }
  584. elseif (empty($_SESSION))
  585. {
  586. return array();
  587. }
  588. $userdata = array();
  589. $_exclude = array_merge(
  590. array('__ci_vars'),
  591. $this->get_flash_keys(),
  592. $this->get_temp_keys()
  593. );
  594. foreach (array_keys($_SESSION) as $key)
  595. {
  596. if ( ! in_array($key, $_exclude, TRUE))
  597. {
  598. $userdata[$key] = $_SESSION[$key];
  599. }
  600. }
  601. return $userdata;
  602. }
  603. // ------------------------------------------------------------------------
  604. /**
  605. * Set userdata
  606. *
  607. * Legacy CI_Session compatibility method
  608. *
  609. * @param mixed $data Session data key or an associative array
  610. * @param mixed $value Value to store
  611. * @return void
  612. */
  613. public function set_userdata($data, $value = NULL)
  614. {
  615. if (is_array($data))
  616. {
  617. foreach ($data as $key => &$value)
  618. {
  619. $_SESSION[$key] = $value;
  620. }
  621. return;
  622. }
  623. $_SESSION[$data] = $value;
  624. }
  625. // ------------------------------------------------------------------------
  626. /**
  627. * Unset userdata
  628. *
  629. * Legacy CI_Session compatibility method
  630. *
  631. * @param mixed $data Session data key(s)
  632. * @return void
  633. */
  634. public function unset_userdata($key)
  635. {
  636. if (is_array($key))
  637. {
  638. foreach ($key as $k)
  639. {
  640. unset($_SESSION[$k]);
  641. }
  642. return;
  643. }
  644. unset($_SESSION[$key]);
  645. }
  646. // ------------------------------------------------------------------------
  647. /**
  648. * All userdata (fetch)
  649. *
  650. * Legacy CI_Session compatibility method
  651. *
  652. * @return array $_SESSION, excluding flash data items
  653. */
  654. public function all_userdata()
  655. {
  656. return $this->userdata();
  657. }
  658. // ------------------------------------------------------------------------
  659. /**
  660. * Has userdata
  661. *
  662. * Legacy CI_Session compatibility method
  663. *
  664. * @param string $key Session data key
  665. * @return bool
  666. */
  667. public function has_userdata($key)
  668. {
  669. return isset($_SESSION[$key]);
  670. }
  671. // ------------------------------------------------------------------------
  672. /**
  673. * Flashdata (fetch)
  674. *
  675. * Legacy CI_Session compatibility method
  676. *
  677. * @param string $key Session data key
  678. * @return mixed Session data value or NULL if not found
  679. */
  680. public function flashdata($key = NULL)
  681. {
  682. if (isset($key))
  683. {
  684. return (isset($_SESSION['__ci_vars'], $_SESSION['__ci_vars'][$key], $_SESSION[$key]) && ! is_int($_SESSION['__ci_vars'][$key]))
  685. ? $_SESSION[$key]
  686. : NULL;
  687. }
  688. $flashdata = array();
  689. if ( ! empty($_SESSION['__ci_vars']))
  690. {
  691. foreach ($_SESSION['__ci_vars'] as $key => &$value)
  692. {
  693. is_int($value) OR $flashdata[$key] = $_SESSION[$key];
  694. }
  695. }
  696. return $flashdata;
  697. }
  698. // ------------------------------------------------------------------------
  699. /**
  700. * Set flashdata
  701. *
  702. * Legacy CI_Session compatibility method
  703. *
  704. * @param mixed $data Session data key or an associative array
  705. * @param mixed $value Value to store
  706. * @return void
  707. */
  708. public function set_flashdata($data, $value = NULL)
  709. {
  710. $this->set_userdata($data, $value);
  711. $this->mark_as_flash(is_array($data) ? array_keys($data) : $data);
  712. }
  713. // ------------------------------------------------------------------------
  714. /**
  715. * Keep flashdata
  716. *
  717. * Legacy CI_Session compatibility method
  718. *
  719. * @param mixed $key Session data key(s)
  720. * @return void
  721. */
  722. public function keep_flashdata($key)
  723. {
  724. $this->mark_as_flash($key);
  725. }
  726. // ------------------------------------------------------------------------
  727. /**
  728. * Temp data (fetch)
  729. *
  730. * Legacy CI_Session compatibility method
  731. *
  732. * @param string $key Session data key
  733. * @return mixed Session data value or NULL if not found
  734. */
  735. public function tempdata($key = NULL)
  736. {
  737. if (isset($key))
  738. {
  739. return (isset($_SESSION['__ci_vars'], $_SESSION['__ci_vars'][$key], $_SESSION[$key]) && is_int($_SESSION['__ci_vars'][$key]))
  740. ? $_SESSION[$key]
  741. : NULL;
  742. }
  743. $tempdata = array();
  744. if ( ! empty($_SESSION['__ci_vars']))
  745. {
  746. foreach ($_SESSION['__ci_vars'] as $key => &$value)
  747. {
  748. is_int($value) && $tempdata[$key] = $_SESSION[$key];
  749. }
  750. }
  751. return $tempdata;
  752. }
  753. // ------------------------------------------------------------------------
  754. /**
  755. * Set tempdata
  756. *
  757. * Legacy CI_Session compatibility method
  758. *
  759. * @param mixed $data Session data key or an associative array of items
  760. * @param mixed $value Value to store
  761. * @param int $ttl Time-to-live in seconds
  762. * @return void
  763. */
  764. public function set_tempdata($data, $value = NULL, $ttl = 300)
  765. {
  766. $this->set_userdata($data, $value);
  767. $this->mark_as_temp(is_array($data) ? array_keys($data) : $data, $ttl);
  768. }
  769. // ------------------------------------------------------------------------
  770. /**
  771. * Unset tempdata
  772. *
  773. * Legacy CI_Session compatibility method
  774. *
  775. * @param mixed $data Session data key(s)
  776. * @return void
  777. */
  778. public function unset_tempdata($key)
  779. {
  780. $this->unmark_temp($key);
  781. }
  782. }