如果用户保持空闲状态 10 分钟,则使 Zend 会话过期


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

我是 zend 的新手,我想问一下如果用户保持空闲 10 分钟,我如何使用户的会话命名空间的特定密钥过期。我在 zend 会话中定义了一个命名空间

 $session = new Zend_Session_Namespace('loginNamespace');

现在,当用户登录时,我在会话命名空间中设置了密钥 loggedIn = 1。现在,如果用户保持空闲状态,我不想使整个会话过期,而只想使该密钥过期。我该怎么做?

在文档中,您可以使用以下命令使密钥过期:

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

那么,你怎么能玩呢?这边:

// 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
}