How to kill sessions within zend?

This is how I set up the sessions

$this -> sess = new Zend_Session_Namespace('user'); $this -> sess -> username = "Bob"; $this -> sess -> admin = "1"; 

And this is how I kill him

 setcookie("mycookiename",md5(rand(10,1200)),time() - (60 * 60),"/",".site.com"); $_SESSION = array(); session_destroy(); $this -> _redirect('/'); 

but it still saves $ this-> sess-> admin as "1" ... the username is gone, but the administrator remains as one. What is the right way to delete ALL client related sessions?

If i do

 $this->sess->admin = 0; 

It then works, but I doubt it is the right way for every session variable that I hold.

I also tried

 setcookie("mycookiename",md5(rand(10,1200)),time() - (60 * 60),"/",".site.com"); Zend_Session::namespaceUnset($this->sess); 

and he did not work, he did not close the sessions.

+7
source share
3 answers

To delete ALL client-related sessions, use this:

 \Zend_Session::destroy( true ); 

This will delete the entire session and also send a header request to the client to delete all cookies associated with the session. You can alternatively set the parameter of this method to false so as not to delete the user's cookies. But note:

Zend_Session :: destroy (true) must be called before PHP is sent. HTTP headers or output buffering must be enabled. It will destroy all persistent data associated with the current session. However, no variables in PHP are affected, so your sessions with names (instances of Zend_Session_Namespace) remain readable.

To remove them, use the following approach:

 $ns = 'auth' $namespace = new \Zend_Session_Namespace( $ns ); $namespace->unsetAll(); 

See here for more details.

+17
source

To destroy a specific session, do

 Zend_Session::namespaceUnset('user'); 
+10
source

you can use

 Zend_Session::destroy($remove_cookie = true, $readonly = true); 

See manual

+4
source

All Articles