|
|
|
@ -16,7 +16,6 @@
|
|
|
|
|
|
|
|
|
|
namespace DtApp\ThinkLibrary\session;
|
|
|
|
|
|
|
|
|
|
use DtApp\ThinkLibrary\facade\Times;
|
|
|
|
|
use think\contract\SessionHandlerInterface;
|
|
|
|
|
use think\db\exception\DataNotFoundException;
|
|
|
|
|
use think\db\exception\DbException;
|
|
|
|
@ -32,7 +31,7 @@ class Mysql implements SessionHandlerInterface
|
|
|
|
|
{
|
|
|
|
|
protected $table_name = 'think_session'; // 表名
|
|
|
|
|
protected $config = [
|
|
|
|
|
'session_expire' => 1800, // Session有效期 单位:秒
|
|
|
|
|
'session_expire' => 3600, // Session有效期 单位:秒
|
|
|
|
|
'session_prefix' => 'think_', // Session前缀
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
@ -45,7 +44,7 @@ class Mysql implements SessionHandlerInterface
|
|
|
|
|
{
|
|
|
|
|
return (string)Db::table($this->table_name)
|
|
|
|
|
->where('session_id', $this->config['session_prefix'] . $sessionId)
|
|
|
|
|
->whereTime('session_expire', '>=', time())
|
|
|
|
|
->where('session_expire', '>=', time())
|
|
|
|
|
->value('session_data', '');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -76,13 +75,13 @@ class Mysql implements SessionHandlerInterface
|
|
|
|
|
{
|
|
|
|
|
$get = Db::table($this->table_name)
|
|
|
|
|
->where('session_id', $this->config['session_prefix'] . $sessionId)
|
|
|
|
|
->whereTime('session_expire', '>=', time())
|
|
|
|
|
->where('session_expire', '>=', time())
|
|
|
|
|
->field('id')
|
|
|
|
|
->find();
|
|
|
|
|
if (empty($get)) {
|
|
|
|
|
$params = [
|
|
|
|
|
'session_id' => $this->config['session_prefix'] . $sessionId,
|
|
|
|
|
'session_expire' => Times::dateRear("Y-m-d H:i:s", $this->config['session_expire']),
|
|
|
|
|
'session_expire' => $this->config['session_expire'] + time(),
|
|
|
|
|
'session_data' => $data
|
|
|
|
|
];
|
|
|
|
|
$result = Db::table($this->table_name)
|
|
|
|
@ -90,7 +89,7 @@ class Mysql implements SessionHandlerInterface
|
|
|
|
|
return $result ? true : false;
|
|
|
|
|
} else {
|
|
|
|
|
$params = [
|
|
|
|
|
'session_expire' => Times::dateRear("Y-m-d H:i:s", $this->config['session_expire']),
|
|
|
|
|
'session_expire' => $this->config['session_expire'] + time(),
|
|
|
|
|
'session_data' => $data
|
|
|
|
|
];
|
|
|
|
|
$result = Db::table($this->table_name)
|
|
|
|
|