【发布时间】:2015-03-20 23:41:04
【问题描述】:
我正在扩展会话提供程序以保留一些必需的数据。我开始编辑AppServiceProvider's boot method:
\Session::extend('desk', function($app)
{
return new Desk();
});
Desk 类看起来像:
namespace App\Services;
use Illuminate\Session\ExistenceAwareInterface;
class Desk implements \SessionHandlerInterface, ExistenceAwareInterface{
/**
* The existence state of the session.
* @var bool
*/
protected $exists;
public function close()
{
return true;
}
public function destroy($session_id)
{
$session = $em->find('Session', $session_id);
$em->remove($session);
$em->flush();
return true;
}
public function gc($maxlifetime)
{
// TODO: Implement gc() method.
}
public function open($save_path, $session_id)
{
return true;
}
public function read($session_id)
{
$session = $em->find('Session', $session_id);
if ($sesion !== null){
$this->exists = true;
return $session->getPayload();
}
}
public function write($session_id, $session_data)
{
$session = $em->find('Session', $session_id);
if ($session === null){
$session = new Session($session_id, $session_data);
$em->persist($session);
}
else{
$session->setPayload($session_data);
}
$em->flush();
$this->exists = true;
}
public function setExists($value)
{
$this->exists = $value;
return $this;
}
}
完成实现后,我将会话配置更改为:
return [
'driver' => 'desk',
'lifetime' => 120,
'expire_on_close' => false,
'encrypt' => false,
'files' => storage_path().'/framework/sessions',
'connection' => null,
'table' => 'sessions',
'lottery' => [2, 100],
'cookie' => 'lote_session',
'path' => '/',
'domain' => null,
'secure' => false,
];
当我加载页面时没有问题,但是在成功登录请求然后刷新页面后,会话过期并且用户再次成为访客。我错过了什么吗?
附加信息:如果我将会话驱动程序恢复为“文件”,一切正常。
【问题讨论】:
标签: php session laravel laravel-5