保存SESSION到SQLITE Save Session ThinkPHP ?php/** * Sqlite保存SESSION * @author WeakSun 52132522@qq.com */namespace Think\Session\Driver;use SessionHandlerInterface;use PDO;class Sqlite implements SessionHandlerInterface {static protected $
保存SESSION到SQLITE Save Session ThinkPHP
<?php /** * Sqlite保存SESSION * @author WeakSun <52132522@qq.com> */ namespace Think\Session\Driver; use SessionHandlerInterface; use PDO; class Sqlite implements SessionHandlerInterface { static protected $tableNameName, $expire, $handler, $nowTime; public function __construct() { empty(static::$expire) && static::$expire = C('SESSION_EXPIRE', null, false) ? C('SESSION_EXPIRE') : ini_get('session.gc_maxlifetime'); empty(static::$nowTime) && static::$nowTime = isset($GLOBALS['_beginTime']) ? $GLOBALS['_beginTime'] : microtime(true); empty(static::$tableNameName) && static::$tableNameName = C('SESSION_TABLE') ? C('SESSION_TABLE') : 'iSession'; $dbFile = TEMP_PATH . 'Caches.tmp'; $isCreate = is_file($dbFile); if (empty(static::$handler)) { static::$handler = new PDO("sqlite:{$dbFile}", null, null, array(PDO::ATTR_PERSISTENT => true)); empty($isCreate) && $this->exec("PRAGMA encoding = 'UTF8';PRAGMA temp_store = 2;PRAGMA auto_vacuum = 0;PRAGMA count_changes = 1;PRAGMA cache_size = 9000;"); $this->chkTable() || $this->createTable(); } } /** * 创建SessionID * @return string */ public function create_sid() { return uniqid(sprintf('%08x', mt_rand(0, 2147483647))); } /** * 打开session * @param string $path * @param string $name * @return boolean */ public function open($path, $name) { return is_object(static::$handler); } /** * 关闭Session * @return boolean */ public function close() { return true; } /** * 读取Session * @param string $id * @return string */ public function read($id = null) { $table = static::$tableNameName; $sth = static::$handler->query("SELECT `value` FROM `{$table}` WHERE `id`='{$id}' AND `expire` > strftime('%s','now') LIMIT 1", PDO::FETCH_NUM); if (!empty($sth)) { list($data) = $sth->fetch(); unset($sth); } else { $data = ''; } return $data; } /** * 写入Session * @param string $id * @param string $data * @return integer */ public function write($id = null, $data = null) { $table = static::$tableNameName; $expire = ceil(static::$expire + static::$nowTime); return $this->exec("REPLACE INTO `{$table}` VALUES('{$id}','{$data}',{$expire})"); } /** * 销毁Session * @param string $id * @return integer */ public function destroy($id = 0) { $table = static::$tableNameName; return $this->exec("DELETE FROM `{$table}` WHERE `id` = '{$id}'"); } /** * 垃圾回收 * @param string $expire * @return integer */ public function gc($expire = 0) { $table = static::$tableNameName; return $this->exec("DELETE FROM `{$table}` WHERE `expire` < strftime('%s','now');VACUUM;"); } /** * 检查当前表是否存在 * @return bool 返回检查结果,存在返回True,失败返回False */ protected function chkTable() { return in_array(static::$tableNameName, $this->getTables()); } /** * 获取当前数据库的数据表列表 * @return array 返回获取到的数据表列表数组 */ protected function getTables() { $tables = $data = array(); $sth = $this->query("SELECT `name` FROM `sqlite_master` WHERE `type` = 'table' UNION ALL SELECT `name` FROM `sqlite_temp_master`"); if (!empty($sth)) { while ($row = $sth->fetch(PDO::FETCH_NUM, PDO::FETCH_ORI_NEXT)) { $tables[] = $row[0]; } unset($sth, $row); } return $tables; } /** * 创建当前数据表 * @return integer 成功返回1,失败返回0 */ protected function createTable() { $tableName = static::$tableNameName; return $this->exec("CREATE TABLE IF NOT EXISTS `{$tableName}` (`id` VARCHAR PRIMARY KEY ON CONFLICT FAIL NOT NULL COLLATE 'NOCASE',`value` TEXT NOT NULL,`expire` INTEGER NOT NULL);"); } public function __call($method, $arguments) { if (method_exists(self::$handler, $method)) { return call_user_func_array(array(self::$handler, $method), $arguments); } else { E(__CLASS__ . ':' . $method . L('_METHOD_NOT_EXIST_')); return; } } }
陳述
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章
R.E.P.O.能量晶體解釋及其做什麼(黃色晶體)
3 週前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.最佳圖形設置
3 週前By尊渡假赌尊渡假赌尊渡假赌
刺客信條陰影:貝殼謎語解決方案
2 週前ByDDD
R.E.P.O.如果您聽不到任何人,如何修復音頻
3 週前By尊渡假赌尊渡假赌尊渡假赌
WWE 2K25:如何解鎖Myrise中的所有內容
3 週前By尊渡假赌尊渡假赌尊渡假赌

熱工具

Atom編輯器mac版下載
最受歡迎的的開源編輯器

SecLists
SecLists是最終安全測試人員的伙伴。它是一個包含各種類型清單的集合,這些清單在安全評估過程中經常使用,而且都在一個地方。 SecLists透過方便地提供安全測試人員可能需要的所有列表,幫助提高安全測試的效率和生產力。清單類型包括使用者名稱、密碼、URL、模糊測試有效載荷、敏感資料模式、Web shell等等。測試人員只需將此儲存庫拉到新的測試機上,他就可以存取所需的每種類型的清單。

DVWA
Damn Vulnerable Web App (DVWA) 是一個PHP/MySQL的Web應用程序,非常容易受到攻擊。它的主要目標是成為安全專業人員在合法環境中測試自己的技能和工具的輔助工具,幫助Web開發人員更好地理解保護網路應用程式的過程,並幫助教師/學生在課堂環境中教授/學習Web應用程式安全性。 DVWA的目標是透過簡單直接的介面練習一些最常見的Web漏洞,難度各不相同。請注意,該軟體中

SublimeText3 Linux新版
SublimeText3 Linux最新版

EditPlus 中文破解版
體積小,語法高亮,不支援程式碼提示功能