Chapitre 25. Zend_Session

Table des matières

25.1. Introduction
25.2. Basic Usage
25.2.1. Tutorial Examples
25.2.2. Iterating Over Session Namespaces
25.2.3. Accessors for Session Namespaces
25.3. Advanced Usage
25.3.1. Starting a Session
25.3.2. Locking Session Namespaces
25.3.3. Session Encapsulation and Controllers
25.3.4. Limiting Instances of Zend_Session to One Per Namespace
25.4. Global Session Management
25.4.1. setOptions()
25.4.2. Options
25.4.3. regenerateId()
25.4.4. rememberMe(integer $seconds)
25.4.5. forgetMe()
25.4.6. sessionExists()
25.4.7. destroy(bool $remove_cookie = true, bool $readonly = true)
25.4.8. stop()
25.4.9. writeClose($readonly = true)
25.4.10. expireSessionCookie()
25.4.11. setSaveHandler(Zend_Session_SaveHandler_Interface $interface)
25.4.12. getInstance($instanceMustExist = false)
25.4.13. namespaceIsset($namespace, $name = null)
25.4.14. namespaceUnset($namespace, $name = null)
25.4.15. namespaceSet($namespace, $name, $value)
25.4.16. namespaceGet($namespace, $name = null)
25.4.17. getIterator()
25.5. Theory

25.1. Introduction

See the most recent published version of this document . Also, the Zend Framework Auth team greatly appreciates your feedback and contributions on our email list: fw-auth@lists.zend.com

With web applications written using PHP, a session represents a logical, one-to-one connection between server-side, persistent state data and a particular user agent client (e.g. web browser). Zend_Session helps manage and preserve session data, a logical complement of cookie data, across multiple page requests by the same client. Unlike cookie data, session data is not stored on the client side, and it is only shared with the client when server-side source code makes the data available via a response to a request from the client. For the purposes of this component and documentation, session data refers to the server-side data managed by Zend_Session.

The Zend_Session component wraps the existing PHP ext/session to provide a standardized, object-oriented interface for working with sessions, including both anonymous and login sessions. Zend_Auth, the authentication component of the ZF uses Zend_Session to store some information associated with login sessions. Since Zend_Session uses the normal PHP session functions internally, all the usual configuration options and settings apply (see http://www.php.net/session ). Thus, a session id, stored either in a cookie or URLs, maintains the association between a client and session state data.

The default ext/session save handler does not solve the problem of maintaining this association, when a client may connect to any sever in a cluster of servers, since session state data is saved to the local server only. A list of additional, appropriate save handlers will be provided, when available.