简体   繁体   中英

Zend Namespace - Check if Session Exists

All,

I am using Zend Framework and Zend_Session to do global session management for my application. I plan to clear all sessions on logout and hence am using the following code:

if($this->sessionExists())
{
    $this->destroy();
}

But it seems like it's not doing a good job.. I am getting an error:

    PHP Warning:  session_destroy() [<a href='function.session-destroy'>
function.session-destroy</a>]: Trying to destroy uninitialized session 

How can I get rid of this error? Is there an alternative to sessionExists()?

Not really answers your question about the error, but is beneficial for the question:

$nsName = 'MyNamespace';
if (Zend_Session::namespaceIsset($nsName)) {
  echo $nsName.' exists';
}

This seems to do the trick..

if($this->isStarted())
{
    if($this->sessionExists())
    {
        $this->namespaceUnset("default");
        $this->forgetMe();
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM