PhpRiot
Follow phpriot on Twitter
Sponsored Link
Download Article
Download this article or the entire “Zend Framework 101” series with all listings and files.




More information
Become Zend Certified

Prepare for the ZCE exam using our quizzes (web or iPad/iPhone). More info...


When you're ready get 7.5% off your exam voucher using voucher CJQNOV23 at the Zend Store
Free iPad/iPhone App
Available on the App Store

  • PHP manual
  • Zend Framework manual
  • Smarty manual
  • PHP articles
  • PHP training

Related Books
PHP Solutions: Dynamic Web Design Made Easy

PHP Solutions: Dynamic Web Design Made Easy

This is the second edition of David Power's highly-respected PHP Solutions: Dynamic Web Design...

PHP for the World Wide Web, Third Edition

PHP for the World Wide Web, Third Edition

With PHP for the World Wide Web, Third Edition: Visual QuickStart Guide , readers can start from...

Zend Framework 101: Zend_Session

Removing Session Data

To remove a value from a session, use PHP's unset() function on the object property. This is demonstrated in Listing 5.

Listing 5 Removing a value from a session namespace (listing-5.php)
<?php
    require_once('Zend/Session.php');
 
    $session = new Zend_Session_Namespace('identity');
    unset($session->username);
?>

In some cases you might want to remove all data in a namespace. You can do this either by looping over all values in the namespace and calling unset() on each one, or you can use the Zend_Session::namespaceUnset(). This method accepts the name of the namespace as its only argument, as demonstrated in Listing 6.

Listing 6 Removing an entire namespace from a session (listing-6.php)
<?php
    require_once('Zend/Session.php');
 
    Zend_Session::namespaceUnset('identity');
?>

You can destroy the entire current session using the Zend_Session::destroy() static function.

In This Article