Session.php 26 KB

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