PageRenderTime 53ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/Zend/Session.php

https://bitbucket.org/simukti/zf1
PHP | 898 lines | 437 code | 133 blank | 328 comment | 83 complexity | c2189dc4f94f9aa2ede57f4affa36430 MD5 | raw file
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Session
  17. * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  18. * @license http://framework.zend.com/license/new-bsd New BSD License
  19. * @version $Id: Session.php 24819 2012-05-28 19:25:03Z rob $
  20. * @since Preview Release 0.2
  21. */
  22. /**
  23. * @see Zend_Session_Abstract
  24. */
  25. require_once 'Zend/Session/Abstract.php';
  26. /**
  27. * @see Zend_Session_Namespace
  28. */
  29. require_once 'Zend/Session/Namespace.php';
  30. /**
  31. * @see Zend_Session_SaveHandler_Interface
  32. */
  33. require_once 'Zend/Session/SaveHandler/Interface.php';
  34. /**
  35. * Zend_Session
  36. *
  37. * @category Zend
  38. * @package Zend_Session
  39. * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  40. * @license http://framework.zend.com/license/new-bsd New BSD License
  41. */
  42. class Zend_Session extends Zend_Session_Abstract
  43. {
  44. /**
  45. * Whether or not Zend_Session is being used with unit tests
  46. *
  47. * @internal
  48. * @var bool
  49. */
  50. public static $_unitTestEnabled = false;
  51. /**
  52. * $_throwStartupException
  53. *
  54. * @var bool|bitset This could also be a combiniation of error codes to catch
  55. */
  56. protected static $_throwStartupExceptions = true;
  57. /**
  58. * Check whether or not the session was started
  59. *
  60. * @var bool
  61. */
  62. private static $_sessionStarted = false;
  63. /**
  64. * Whether or not the session id has been regenerated this request.
  65. *
  66. * Id regeneration state
  67. * <0 - regenerate requested when session is started
  68. * 0 - do nothing
  69. * >0 - already called session_regenerate_id()
  70. *
  71. * @var int
  72. */
  73. private static $_regenerateIdState = 0;
  74. /**
  75. * Private list of php's ini values for ext/session
  76. * null values will default to the php.ini value, otherwise
  77. * the value below will overwrite the default ini value, unless
  78. * the user has set an option explicity with setOptions()
  79. *
  80. * @var array
  81. */
  82. private static $_defaultOptions = array(
  83. 'save_path' => null,
  84. 'name' => null, /* this should be set to a unique value for each application */
  85. 'save_handler' => null,
  86. //'auto_start' => null, /* intentionally excluded (see manual) */
  87. 'gc_probability' => null,
  88. 'gc_divisor' => null,
  89. 'gc_maxlifetime' => null,
  90. 'serialize_handler' => null,
  91. 'cookie_lifetime' => null,
  92. 'cookie_path' => null,
  93. 'cookie_domain' => null,
  94. 'cookie_secure' => null,
  95. 'cookie_httponly' => null,
  96. 'use_cookies' => null,
  97. 'use_only_cookies' => 'on',
  98. 'referer_check' => null,
  99. 'entropy_file' => null,
  100. 'entropy_length' => null,
  101. 'cache_limiter' => null,
  102. 'cache_expire' => null,
  103. 'use_trans_sid' => null,
  104. 'bug_compat_42' => null,
  105. 'bug_compat_warn' => null,
  106. 'hash_function' => null,
  107. 'hash_bits_per_character' => null
  108. );
  109. /**
  110. * List of options pertaining to Zend_Session that can be set by developers
  111. * using Zend_Session::setOptions(). This list intentionally duplicates
  112. * the individual declaration of static "class" variables by the same names.
  113. *
  114. * @var array
  115. */
  116. private static $_localOptions = array(
  117. 'strict' => '_strict',
  118. 'remember_me_seconds' => '_rememberMeSeconds',
  119. 'throw_startup_exceptions' => '_throwStartupExceptions'
  120. );
  121. /**
  122. * Whether or not write close has been performed.
  123. *
  124. * @var bool
  125. */
  126. private static $_writeClosed = false;
  127. /**
  128. * Whether or not session id cookie has been deleted
  129. *
  130. * @var bool
  131. */
  132. private static $_sessionCookieDeleted = false;
  133. /**
  134. * Whether or not session has been destroyed via session_destroy()
  135. *
  136. * @var bool
  137. */
  138. private static $_destroyed = false;
  139. /**
  140. * Whether or not session must be initiated before usage
  141. *
  142. * @var bool
  143. */
  144. private static $_strict = false;
  145. /**
  146. * Default number of seconds the session will be remembered for when asked to be remembered
  147. *
  148. * @var int
  149. */
  150. private static $_rememberMeSeconds = 1209600; // 2 weeks
  151. /**
  152. * Whether the default options listed in Zend_Session::$_localOptions have been set
  153. *
  154. * @var bool
  155. */
  156. private static $_defaultOptionsSet = false;
  157. /**
  158. * A reference to the set session save handler
  159. *
  160. * @var Zend_Session_SaveHandler_Interface
  161. */
  162. private static $_saveHandler = null;
  163. /**
  164. * Constructor overriding - make sure that a developer cannot instantiate
  165. */
  166. protected function __construct()
  167. {
  168. }
  169. /**
  170. * setOptions - set both the class specified
  171. *
  172. * @param array $userOptions - pass-by-keyword style array of <option name, option value> pairs
  173. * @throws Zend_Session_Exception
  174. * @return void
  175. */
  176. public static function setOptions(array $userOptions = array())
  177. {
  178. // set default options on first run only (before applying user settings)
  179. if (!self::$_defaultOptionsSet) {
  180. foreach (self::$_defaultOptions as $defaultOptionName => $defaultOptionValue) {
  181. if (isset(self::$_defaultOptions[$defaultOptionName])) {
  182. ini_set("session.$defaultOptionName", $defaultOptionValue);
  183. }
  184. }
  185. self::$_defaultOptionsSet = true;
  186. }
  187. // set the options the user has requested to set
  188. foreach ($userOptions as $userOptionName => $userOptionValue) {
  189. $userOptionName = strtolower($userOptionName);
  190. // set the ini based values
  191. if (array_key_exists($userOptionName, self::$_defaultOptions)) {
  192. ini_set("session.$userOptionName", $userOptionValue);
  193. }
  194. elseif (isset(self::$_localOptions[$userOptionName])) {
  195. self::${self::$_localOptions[$userOptionName]} = $userOptionValue;
  196. }
  197. else {
  198. /** @see Zend_Session_Exception */
  199. require_once 'Zend/Session/Exception.php';
  200. throw new Zend_Session_Exception("Unknown option: $userOptionName = $userOptionValue");
  201. }
  202. }
  203. }
  204. /**
  205. * getOptions()
  206. *
  207. * @param string $optionName OPTIONAL
  208. * @return array|string
  209. */
  210. public static function getOptions($optionName = null)
  211. {
  212. $options = array();
  213. foreach (ini_get_all('session') as $sysOptionName => $sysOptionValues) {
  214. $options[substr($sysOptionName, 8)] = $sysOptionValues['local_value'];
  215. }
  216. foreach (self::$_localOptions as $localOptionName => $localOptionMemberName) {
  217. $options[$localOptionName] = self::${$localOptionMemberName};
  218. }
  219. if ($optionName) {
  220. if (array_key_exists($optionName, $options)) {
  221. return $options[$optionName];
  222. }
  223. return null;
  224. }
  225. return $options;
  226. }
  227. /**
  228. * setSaveHandler() - Session Save Handler assignment
  229. *
  230. * @param Zend_Session_SaveHandler_Interface $interface
  231. * @return void
  232. */
  233. public static function setSaveHandler(Zend_Session_SaveHandler_Interface $saveHandler)
  234. {
  235. self::$_saveHandler = $saveHandler;
  236. if (self::$_unitTestEnabled) {
  237. return;
  238. }
  239. session_set_save_handler(
  240. array(&$saveHandler, 'open'),
  241. array(&$saveHandler, 'close'),
  242. array(&$saveHandler, 'read'),
  243. array(&$saveHandler, 'write'),
  244. array(&$saveHandler, 'destroy'),
  245. array(&$saveHandler, 'gc')
  246. );
  247. }
  248. /**
  249. * getSaveHandler() - Get the session Save Handler
  250. *
  251. * @return Zend_Session_SaveHandler_Interface
  252. */
  253. public static function getSaveHandler()
  254. {
  255. return self::$_saveHandler;
  256. }
  257. /**
  258. * regenerateId() - Regenerate the session id. Best practice is to call this after
  259. * session is started. If called prior to session starting, session id will be regenerated
  260. * at start time.
  261. *
  262. * @throws Zend_Session_Exception
  263. * @return void
  264. */
  265. public static function regenerateId()
  266. {
  267. if (!self::$_unitTestEnabled && headers_sent($filename, $linenum)) {
  268. /** @see Zend_Session_Exception */
  269. require_once 'Zend/Session/Exception.php';
  270. throw new Zend_Session_Exception("You must call " . __CLASS__ . '::' . __FUNCTION__ .
  271. "() before any output has been sent to the browser; output started in {$filename}/{$linenum}");
  272. }
  273. if ( !self::$_sessionStarted ) {
  274. self::$_regenerateIdState = -1;
  275. } else {
  276. if (!self::$_unitTestEnabled) {
  277. session_regenerate_id(true);
  278. }
  279. self::$_regenerateIdState = 1;
  280. }
  281. }
  282. /**
  283. * rememberMe() - Write a persistent cookie that expires after a number of seconds in the future. If no number of
  284. * seconds is specified, then this defaults to self::$_rememberMeSeconds. Due to clock errors on end users' systems,
  285. * large values are recommended to avoid undesirable expiration of session cookies.
  286. *
  287. * @param int $seconds OPTIONAL specifies TTL for cookie in seconds from present time
  288. * @return void
  289. */
  290. public static function rememberMe($seconds = null)
  291. {
  292. $seconds = (int) $seconds;
  293. $seconds = ($seconds > 0) ? $seconds : self::$_rememberMeSeconds;
  294. self::rememberUntil($seconds);
  295. }
  296. /**
  297. * forgetMe() - Write a volatile session cookie, removing any persistent cookie that may have existed. The session
  298. * would end upon, for example, termination of a web browser program.
  299. *
  300. * @return void
  301. */
  302. public static function forgetMe()
  303. {
  304. self::rememberUntil(0);
  305. }
  306. /**
  307. * rememberUntil() - This method does the work of changing the state of the session cookie and making
  308. * sure that it gets resent to the browser via regenerateId()
  309. *
  310. * @param int $seconds
  311. * @return void
  312. */
  313. public static function rememberUntil($seconds = 0)
  314. {
  315. if (self::$_unitTestEnabled) {
  316. self::regenerateId();
  317. return;
  318. }
  319. $cookieParams = session_get_cookie_params();
  320. session_set_cookie_params(
  321. $seconds,
  322. $cookieParams['path'],
  323. $cookieParams['domain'],
  324. $cookieParams['secure']
  325. );
  326. // normally "rememberMe()" represents a security context change, so should use new session id
  327. self::regenerateId();
  328. }
  329. /**
  330. * sessionExists() - whether or not a session exists for the current request
  331. *
  332. * @return bool
  333. */
  334. public static function sessionExists()
  335. {
  336. if ((bool)ini_get('session.use_cookies') == true && isset($_COOKIE[session_name()])) {
  337. return true;
  338. } elseif ((bool)ini_get('session.use_only_cookies') == false && isset($_REQUEST[session_name()])) {
  339. return true;
  340. } elseif (self::$_unitTestEnabled) {
  341. return true;
  342. }
  343. return false;
  344. }
  345. /**
  346. * Whether or not session has been destroyed via session_destroy()
  347. *
  348. * @return bool
  349. */
  350. public static function isDestroyed()
  351. {
  352. return self::$_destroyed;
  353. }
  354. /**
  355. * start() - Start the session.
  356. *
  357. * @param bool|array $options OPTIONAL Either user supplied options, or flag indicating if start initiated automatically
  358. * @throws Zend_Session_Exception
  359. * @return void
  360. */
  361. public static function start($options = false)
  362. {
  363. // Check to see if we've been passed an invalid session ID
  364. if ( self::getId() && !self::_checkId(self::getId()) ) {
  365. // Generate a valid, temporary replacement
  366. self::setId(md5(self::getId()));
  367. // Force a regenerate after session is started
  368. self::$_regenerateIdState = -1;
  369. }
  370. if (self::$_sessionStarted && self::$_destroyed) {
  371. require_once 'Zend/Session/Exception.php';
  372. throw new Zend_Session_Exception('The session was explicitly destroyed during this request, attempting to re-start is not allowed.');
  373. }
  374. if (self::$_sessionStarted) {
  375. return; // already started
  376. }
  377. // make sure our default options (at the least) have been set
  378. if (!self::$_defaultOptionsSet) {
  379. self::setOptions(is_array($options) ? $options : array());
  380. }
  381. // In strict mode, do not allow auto-starting Zend_Session, such as via "new Zend_Session_Namespace()"
  382. if (self::$_strict && $options === true) {
  383. /** @see Zend_Session_Exception */
  384. require_once 'Zend/Session/Exception.php';
  385. throw new Zend_Session_Exception('You must explicitly start the session with Zend_Session::start() when session options are set to strict.');
  386. }
  387. $filename = $linenum = null;
  388. if (!self::$_unitTestEnabled && headers_sent($filename, $linenum)) {
  389. /** @see Zend_Session_Exception */
  390. require_once 'Zend/Session/Exception.php';
  391. throw new Zend_Session_Exception("Session must be started before any output has been sent to the browser;"
  392. . " output started in {$filename}/{$linenum}");
  393. }
  394. // See http://www.php.net/manual/en/ref.session.php for explanation
  395. if (!self::$_unitTestEnabled && defined('SID')) {
  396. /** @see Zend_Session_Exception */
  397. require_once 'Zend/Session/Exception.php';
  398. throw new Zend_Session_Exception('session has already been started by session.auto-start or session_start()');
  399. }
  400. /**
  401. * Hack to throw exceptions on start instead of php errors
  402. * @see http://framework.zend.com/issues/browse/ZF-1325
  403. */
  404. $errorLevel = (is_int(self::$_throwStartupExceptions)) ? self::$_throwStartupExceptions : E_ALL;
  405. /** @see Zend_Session_Exception */
  406. if (!self::$_unitTestEnabled) {
  407. if (self::$_throwStartupExceptions) {
  408. require_once 'Zend/Session/Exception.php';
  409. set_error_handler(array('Zend_Session_Exception', 'handleSessionStartError'), $errorLevel);
  410. }
  411. $startedCleanly = session_start();
  412. if (self::$_throwStartupExceptions) {
  413. restore_error_handler();
  414. }
  415. if (!$startedCleanly || Zend_Session_Exception::$sessionStartError != null) {
  416. if (self::$_throwStartupExceptions) {
  417. set_error_handler(array('Zend_Session_Exception', 'handleSilentWriteClose'), $errorLevel);
  418. }
  419. session_write_close();
  420. if (self::$_throwStartupExceptions) {
  421. restore_error_handler();
  422. throw new Zend_Session_Exception(__CLASS__ . '::' . __FUNCTION__ . '() - ' . Zend_Session_Exception::$sessionStartError);
  423. }
  424. }
  425. }
  426. parent::$_readable = true;
  427. parent::$_writable = true;
  428. self::$_sessionStarted = true;
  429. if (self::$_regenerateIdState === -1) {
  430. self::regenerateId();
  431. }
  432. // run validators if they exist
  433. if (isset($_SESSION['__ZF']['VALID'])) {
  434. self::_processValidators();
  435. }
  436. self::_processStartupMetadataGlobal();
  437. }
  438. /**
  439. * Perform a hash-bits check on the session ID
  440. *
  441. * @param string $id Session ID
  442. * @return bool
  443. */
  444. protected static function _checkId($id)
  445. {
  446. $hashBitsPerChar = ini_get('session.hash_bits_per_character');
  447. if (!$hashBitsPerChar) {
  448. $hashBitsPerChar = 5; // the default value
  449. }
  450. switch($hashBitsPerChar) {
  451. case 4: $pattern = '^[0-9a-f]*$'; break;
  452. case 5: $pattern = '^[0-9a-v]*$'; break;
  453. case 6: $pattern = '^[0-9a-zA-Z-,]*$'; break;
  454. }
  455. return preg_match('#'.$pattern.'#', $id);
  456. }
  457. /**
  458. * _processGlobalMetadata() - this method initizes the sessions GLOBAL
  459. * metadata, mostly global data expiration calculations.
  460. *
  461. * @return void
  462. */
  463. private static function _processStartupMetadataGlobal()
  464. {
  465. // process global metadata
  466. if (isset($_SESSION['__ZF'])) {
  467. // expire globally expired values
  468. foreach ($_SESSION['__ZF'] as $namespace => $namespace_metadata) {
  469. // Expire Namespace by Time (ENT)
  470. if (isset($namespace_metadata['ENT']) && ($namespace_metadata['ENT'] > 0) && (time() > $namespace_metadata['ENT']) ) {
  471. unset($_SESSION[$namespace]);
  472. unset($_SESSION['__ZF'][$namespace]);
  473. }
  474. // Expire Namespace by Global Hop (ENGH) if it wasnt expired above
  475. if (isset($_SESSION['__ZF'][$namespace]) && isset($namespace_metadata['ENGH']) && $namespace_metadata['ENGH'] >= 1) {
  476. $_SESSION['__ZF'][$namespace]['ENGH']--;
  477. if ($_SESSION['__ZF'][$namespace]['ENGH'] === 0) {
  478. if (isset($_SESSION[$namespace])) {
  479. parent::$_expiringData[$namespace] = $_SESSION[$namespace];
  480. unset($_SESSION[$namespace]);
  481. }
  482. unset($_SESSION['__ZF'][$namespace]);
  483. }
  484. }
  485. // Expire Namespace Variables by Time (ENVT)
  486. if (isset($namespace_metadata['ENVT'])) {
  487. foreach ($namespace_metadata['ENVT'] as $variable => $time) {
  488. if (time() > $time) {
  489. unset($_SESSION[$namespace][$variable]);
  490. unset($_SESSION['__ZF'][$namespace]['ENVT'][$variable]);
  491. }
  492. }
  493. if (empty($_SESSION['__ZF'][$namespace]['ENVT'])) {
  494. unset($_SESSION['__ZF'][$namespace]['ENVT']);
  495. }
  496. }
  497. // Expire Namespace Variables by Global Hop (ENVGH)
  498. if (isset($namespace_metadata['ENVGH'])) {
  499. foreach ($namespace_metadata['ENVGH'] as $variable => $hops) {
  500. $_SESSION['__ZF'][$namespace]['ENVGH'][$variable]--;
  501. if ($_SESSION['__ZF'][$namespace]['ENVGH'][$variable] === 0) {
  502. if (isset($_SESSION[$namespace][$variable])) {
  503. parent::$_expiringData[$namespace][$variable] = $_SESSION[$namespace][$variable];
  504. unset($_SESSION[$namespace][$variable]);
  505. }
  506. unset($_SESSION['__ZF'][$namespace]['ENVGH'][$variable]);
  507. }
  508. }
  509. if (empty($_SESSION['__ZF'][$namespace]['ENVGH'])) {
  510. unset($_SESSION['__ZF'][$namespace]['ENVGH']);
  511. }
  512. }
  513. if (isset($namespace) && empty($_SESSION['__ZF'][$namespace])) {
  514. unset($_SESSION['__ZF'][$namespace]);
  515. }
  516. }
  517. }
  518. if (isset($_SESSION['__ZF']) && empty($_SESSION['__ZF'])) {
  519. unset($_SESSION['__ZF']);
  520. }
  521. }
  522. /**
  523. * isStarted() - convenience method to determine if the session is already started.
  524. *
  525. * @return bool
  526. */
  527. public static function isStarted()
  528. {
  529. return self::$_sessionStarted;
  530. }
  531. /**
  532. * isRegenerated() - convenience method to determine if session_regenerate_id()
  533. * has been called during this request by Zend_Session.
  534. *
  535. * @return bool
  536. */
  537. public static function isRegenerated()
  538. {
  539. return ( (self::$_regenerateIdState > 0) ? true : false );
  540. }
  541. /**
  542. * getId() - get the current session id
  543. *
  544. * @return string
  545. */
  546. public static function getId()
  547. {
  548. return session_id();
  549. }
  550. /**
  551. * setId() - set an id to a user specified id
  552. *
  553. * @throws Zend_Session_Exception
  554. * @param string $id
  555. * @return void
  556. */
  557. public static function setId($id)
  558. {
  559. if (!self::$_unitTestEnabled && defined('SID')) {
  560. /** @see Zend_Session_Exception */
  561. require_once 'Zend/Session/Exception.php';
  562. throw new Zend_Session_Exception('The session has already been started. The session id must be set first.');
  563. }
  564. if (!self::$_unitTestEnabled && headers_sent($filename, $linenum)) {
  565. /** @see Zend_Session_Exception */
  566. require_once 'Zend/Session/Exception.php';
  567. throw new Zend_Session_Exception("You must call ".__CLASS__.'::'.__FUNCTION__.
  568. "() before any output has been sent to the browser; output started in {$filename}/{$linenum}");
  569. }
  570. if (!is_string($id) || $id === '') {
  571. /** @see Zend_Session_Exception */
  572. require_once 'Zend/Session/Exception.php';
  573. throw new Zend_Session_Exception('You must provide a non-empty string as a session identifier.');
  574. }
  575. session_id($id);
  576. }
  577. /**
  578. * registerValidator() - register a validator that will attempt to validate this session for
  579. * every future request
  580. *
  581. * @param Zend_Session_Validator_Interface $validator
  582. * @return void
  583. */
  584. public static function registerValidator(Zend_Session_Validator_Interface $validator)
  585. {
  586. $validator->setup();
  587. }
  588. /**
  589. * stop() - Disable write access. Optionally disable read (not implemented).
  590. *
  591. * @return void
  592. */
  593. public static function stop()
  594. {
  595. parent::$_writable = false;
  596. }
  597. /**
  598. * writeClose() - Shutdown the sesssion, close writing and detach $_SESSION from the back-end storage mechanism.
  599. * This will complete the internal data transformation on this request.
  600. *
  601. * @param bool $readonly - OPTIONAL remove write access (i.e. throw error if Zend_Session's attempt writes)
  602. * @return void
  603. */
  604. public static function writeClose($readonly = true)
  605. {
  606. if (self::$_unitTestEnabled) {
  607. return;
  608. }
  609. if (self::$_writeClosed) {
  610. return;
  611. }
  612. if ($readonly) {
  613. parent::$_writable = false;
  614. }
  615. session_write_close();
  616. self::$_writeClosed = true;
  617. }
  618. /**
  619. * destroy() - This is used to destroy session data, and optionally, the session cookie itself
  620. *
  621. * @param bool $remove_cookie - OPTIONAL remove session id cookie, defaults to true (remove cookie)
  622. * @param bool $readonly - OPTIONAL remove write access (i.e. throw error if Zend_Session's attempt writes)
  623. * @return void
  624. */
  625. public static function destroy($remove_cookie = true, $readonly = true)
  626. {
  627. if (self::$_unitTestEnabled) {
  628. return;
  629. }
  630. if (self::$_destroyed) {
  631. return;
  632. }
  633. if ($readonly) {
  634. parent::$_writable = false;
  635. }
  636. session_destroy();
  637. self::$_destroyed = true;
  638. if ($remove_cookie) {
  639. self::expireSessionCookie();
  640. }
  641. }
  642. /**
  643. * expireSessionCookie() - Sends an expired session id cookie, causing the client to delete the session cookie
  644. *
  645. * @return void
  646. */
  647. public static function expireSessionCookie()
  648. {
  649. if (self::$_unitTestEnabled) {
  650. return;
  651. }
  652. if (self::$_sessionCookieDeleted) {
  653. return;
  654. }
  655. self::$_sessionCookieDeleted = true;
  656. if (isset($_COOKIE[session_name()])) {
  657. $cookie_params = session_get_cookie_params();
  658. setcookie(
  659. session_name(),
  660. false,
  661. 315554400, // strtotime('1980-01-01'),
  662. $cookie_params['path'],
  663. $cookie_params['domain'],
  664. $cookie_params['secure']
  665. );
  666. }
  667. }
  668. /**
  669. * _processValidator() - internal function that is called in the existence of VALID metadata
  670. *
  671. * @throws Zend_Session_Exception
  672. * @return void
  673. */
  674. private static function _processValidators()
  675. {
  676. foreach ($_SESSION['__ZF']['VALID'] as $validator_name => $valid_data) {
  677. if (!class_exists($validator_name)) {
  678. require_once 'Zend/Loader.php';
  679. Zend_Loader::loadClass($validator_name);
  680. }
  681. $validator = new $validator_name;
  682. if ($validator->validate() === false) {
  683. /** @see Zend_Session_Exception */
  684. require_once 'Zend/Session/Exception.php';
  685. throw new Zend_Session_Exception("This session is not valid according to {$validator_name}.");
  686. }
  687. }
  688. }
  689. /**
  690. * namespaceIsset() - check to see if a namespace is set
  691. *
  692. * @param string $namespace
  693. * @return bool
  694. */
  695. public static function namespaceIsset($namespace)
  696. {
  697. return parent::_namespaceIsset($namespace);
  698. }
  699. /**
  700. * namespaceUnset() - unset a namespace or a variable within a namespace
  701. *
  702. * @param string $namespace
  703. * @throws Zend_Session_Exception
  704. * @return void
  705. */
  706. public static function namespaceUnset($namespace)
  707. {
  708. parent::_namespaceUnset($namespace);
  709. Zend_Session_Namespace::resetSingleInstance($namespace);
  710. }
  711. /**
  712. * namespaceGet() - get all variables in a namespace
  713. * Deprecated: Use getIterator() in Zend_Session_Namespace.
  714. *
  715. * @param string $namespace
  716. * @return array
  717. */
  718. public static function namespaceGet($namespace)
  719. {
  720. return parent::_namespaceGetAll($namespace);
  721. }
  722. /**
  723. * getIterator() - return an iteratable object for use in foreach and the like,
  724. * this completes the IteratorAggregate interface
  725. *
  726. * @throws Zend_Session_Exception
  727. * @return ArrayObject
  728. */
  729. public static function getIterator()
  730. {
  731. if (parent::$_readable === false) {
  732. /** @see Zend_Session_Exception */
  733. require_once 'Zend/Session/Exception.php';
  734. throw new Zend_Session_Exception(parent::_THROW_NOT_READABLE_MSG);
  735. }
  736. $spaces = array();
  737. if (isset($_SESSION)) {
  738. $spaces = array_keys($_SESSION);
  739. foreach($spaces as $key => $space) {
  740. if (!strncmp($space, '__', 2) || !is_array($_SESSION[$space])) {
  741. unset($spaces[$key]);
  742. }
  743. }
  744. }
  745. return new ArrayObject(array_merge($spaces, array_keys(parent::$_expiringData)));
  746. }
  747. /**
  748. * isWritable() - returns a boolean indicating if namespaces can write (use setters)
  749. *
  750. * @return bool
  751. */
  752. public static function isWritable()
  753. {
  754. return parent::$_writable;
  755. }
  756. /**
  757. * isReadable() - returns a boolean indicating if namespaces can write (use setters)
  758. *
  759. * @return bool
  760. */
  761. public static function isReadable()
  762. {
  763. return parent::$_readable;
  764. }
  765. }