2017-04-24 38 views
1

我有一个鉴别会话不会过期的问题,这是我的认证代码:Zend框架2:设置会话认证超时

$adapter = $this->getServiceLocator()->get('doctrine.authenticationadapter.orm_default'); 
$adapter->setOptions(array(
    'objectManager' => $this->getEntityManager(), 
    'identityClass' => 'Application\Entity\User', 
    'identityProperty' => 'email', 
    'credentialProperty' => 'password')); 

$adapter->setIdentityValue($mail); 
$adapter->setCredentialValue($password); 
$authService = new AuthenticationService(); 
$result = $authService->authenticate($adapter); 

if ($result->isValid()) 
{ 
    $identity = $result->getIdentity(); 
    $authService->getStorage()->write($identity); 
    echo "valide"; 
} 
else 
    echo "invalide"; 

感谢。

+0

你是否自己编写了所有的代码?如果不是,您使用了哪些外部模块?你有配置中的任何会话配置('/ config/autoload/*',但也可以在任何模块配置吗?'Module.php'中的额外配置如何? –

+0

@ThomasDutrion no我没有什么其他关于会话配置或关于auth config。 – user3911183

+0

然后它可能来自您的底层PHP配置。 –

回答

0

这是我如何解决我的问题:

if ($result->isValid()) 
{ 
    $session = new Container('Zend_Auth'); 
    $session->setExpirationSeconds(1800); 
    $identity = $result->getIdentity(); 
    $authService->getStorage()->write($identity); 
    echo "valide"; 
} 
else 
    echo "invalide"; 

我得到的对象会话Zend_Auth,然后我编辑的到期时间值。 希望它有帮助!