Pages

Tuesday, November 9, 2010

Zend Framework Session handling

Starting a Session

If you want all requests to have a session facilitated by Zend_Session, then start the session in the bootstrap file:
Example #1 Starting the Global Session
  1. Zend_Session::start();
By starting the session in the bootstrap file, you avoid the possibility that your session might be started after headers have been sent to the browser, which results in an exception, and possibly a broken page for website viewers. Various advanced features require Zend_Session::start() first

Example #5 Accessing Session Data
  1. $namespace = new Zend_Session_Namespace(); // default namespace
  2.  
  3. $namespace->foo = 100;
  4.  
  5. echo "\$namespace->foo = $namespace->foo\n";
  6.  
  7. if (!isset($namespace->bar)) {
  8.     echo "\$namespace->bar not set\n";
  9. }
  10.  
  11. unset($namespace->foo);

No comments:

Post a Comment