Expire the Zend session if the user remains idle for 10 minutes

江枫思渺然 提交于 2020-01-13 06:02:28

问题


I am new to zend and I want to ask how can I expire a user's session namespace's particular key if a user remains idle for 10 minutes. I have a namespace defined in zend session as

 $session = new Zend_Session_Namespace('loginNamespace');

now when the user logs in I set the key loggedIn = 1 in session namespace. Now I want to expire not the whole session if the user remains idle but only that key. how can I do that?


回答1:


From the documentation, you can expire a key using:

$session->setExpirationSeconds( 600, 'key' );

So, how can you play with that? This way:

// Set "dummy" key with expiration
$session->setExpirationSeconds( 600, 'key' );

// Then, you can check if this key exists
if ( $session->key ) {
    // Just reset the expiration
    $session->setExpirationSeconds( 600, 'key' );
}
else {
    // Delete your other key
}


来源:https://stackoverflow.com/questions/10975781/expire-the-zend-session-if-the-user-remains-idle-for-10-minutes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!