php - Extended Session in L5 does not persist between requests -
i extending session provider in order persist required data. started editing appserviceprovider's boot method
:
\session::extend('desk', function($app) { return new desk(); });
desk
class looks like:
namespace app\services; use illuminate\session\existenceawareinterface; class desk implements \sessionhandlerinterface, existenceawareinterface{ /** * existence state of 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; } }
after finish implementation, changed session config 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, ];
when load page there not problem, after success login request , then, refresh page, session expires , user guest again. miss something?
additional information: if revert session driver "file", goes fine.
well, others need/want extends session provider me, pay attention session's table structure. mistake payload
column set as:
payload varchar(255) not null
because of laravel serialization data, payload value has more 255 characters length, in consequence, break data , make inconsistent. can consider:
payload text not null
Comments
Post a Comment