Cphalcon: $this->session->destroy(); does not work!

Created on 21 Jul 2015  路  7Comments  路  Source: phalcon/cphalcon

i have:

$di->setShared('session', function() {
 $session = new Phalcon\Session\Adapter\Files();
 $session->start();
 return $session;
});

On controller:

 $this->session->set(self::BTS_SESSION_USER_ID, $o_user->getIduser());

and after:

$this->session->destroy();
 var_dump($this->session->get(self::BTS_SESSION_USER_NAME));

And response with data!.

not a bug

All 7 comments

destroy() calls session_destroy() which is a PHP built-in function:

https://github.com/phalcon/cphalcon/blob/2.0.x/phalcon/session/adapter.zep#L220

@andresgutierrez i changed redis session to native session:

$di->setShared('session', function() {
$session = new Phalcon\Session\Adapter\Files();
$session->start();
return $session;

});

On controller:

$this->session->set(self::BTS_SESSION_USER_ID, $o_user->getIduser());

and after:

$this->session->destroy();
var_dump($this->session->get(self::BTS_SESSION_USER_NAME));

And response with data!.
The same problem!...

In the description of session_destroy:

session_destroy() destroys all of the data associated with the current session. It does not unset any of the global variables associated with the session, or unset the session cookie. To use the session variables again, session_start() has to be called.

In order to kill the session altogether, like to log the user out, the session id must also be unset. If a cookie is used to propagate the session id (default behavior), then the session cookie must be deleted. setcookie() may be used for that.

I added:

 setcookie(session_name(), '', time()-42000, '/'); 
 session_destroy();
 var_dump($this->session->get(self::BTS_SESSION_USER_NAME));

But The same problem!,can you help me please, how do you remove all session data?

session_destroy() does not remove any data from the superglobal $_SESSION, you have to remove it:

$this->session->remove(self::BTS_SESSION_USER_NAME);

Or force a redirect and then the data will be cleared.

Ok thanks! @andresgutierrez ,

i used:

session_unset();
session_regenerate_id(true);
var_dump($this->session->get(self::BTS_SESSION_USER_NAME));

And response NULL!,

works!, the reason that i want to destroy all session data, not only one key, for example for logout

there is any way to do that? with : $this->session-> ?

I added an option to Phalcon 2.0.7 to remove data in _SESSION:

$this->session->destroy(true);
Was this page helpful?
0 / 5 - 0 ratings