简体   繁体   中英

zend2: how to destroy exact session?

I am new to Zend2. I dont know how to destroy the particular session.

$check_username = $session->offsetExists('sess_chk_usr_name');
if(empty($check_username))
{
   $session->offsetSet('sess_chk_usr_name', 'test user');
}

I need to remove the session sess_chk_usr_name, please help.

I realise it's been answered, but it gets asked a lot. Session containers in ZF2 are essentially ArrayObjects , with the flag ARRAY_AS_PROPS set. What that means is they behave like an array AND an object, so not only can you use the methods the object supplies to access properties, you can act on them just like an array (although it should be noted that the array_* family of functions don't work)

Setters

$session = new Container('foo');

// these are all equivalent means to the same end
$session['bar'] = 'foobar';

$session->bar = 'foobar';

$session->offsetSet('bar', 'foobar'); 

Getters

$bar = $session['bar'];

$bar = $session->bar;

$bar = $session->offsetGet('bar');

isset()

$test = isset($session['bar']);

$test = isset($session->bar);

$test = $session->offsetExists('bar');

unset()

unset($session['bar']);

unset($session->bar);

$session->offsetUnset('bar');

To destroy a particular session:\\

 $session->getManager()->getStorage()->clear('ses_variable');

  or

 unset($_SESSION['ses_variable']); 

 or

 session_destroy('ses_variable');

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