用文件管理 SESSION
只需在 application.ini 中作以下設置,並保證目標路徑可寫即可。
;=========== SESSION 設置
resources.session.save_path = APPLICATION_PATH "/../data/sessions"
resources.session.use_trans_sid = 1
resources.session.use_only_cookies = 0
resources.session.remember_me_seconds = 86400 ; 1 天
resources.session.gc_maxlifetime = 86400
用數據庫管理 SESSION
首先,建表:
-- SESSION 數據表
CREATE TABLE session (
id char(32),
modified int,
lifetime int,
data text,
PRIMARY KEY (id)
);
然後,在 application.ini 中作以下設置:
;=========== SESSION設置
resources.session.saveHandler.class = "Zend_Session_SaveHandler_DbTable"
resources.session.saveHandler.options.name = "session"
resources.session.saveHandler.options.primary = "id"
resources.session.saveHandler.options.modifiedColumn = "modified"
resources.session.saveHandler.options.dataColumn = "data"
resources.session.saveHandler.options.lifetimeColumn = "lifetime"
resources.session.use_trans_sid = 1
resources.session.use_only_cookies = 0
resources.session.remember_me_seconds = 86400 ; 1天
resources.session.gc_maxlifetime = 86400
實例化session,並賦值
$mysession = new Zend_Session_Namespace('mysession');
$mysession->myname = 'this is my name.';
$mysession->mynumber = "888888";
$mysession->my = 'this is a session test';
//$mysession->setExpirationHops(5);// 5 次訪問後,會話過期
//$mysession->setExpirationSeconds(60);//命名空間 "user" 將在第一次訪問後 60 秒,或者訪問
//這裡實例一個命名空間為mysession2的會話
$mysession2 = new Zend_Session_Namespace('mysession2');
$mysession2->pass = '123456';
//訪問session
$mysession = new Zend_Session_Namespace('mysession');
$this->view->str = $mysession->my;
//銷毀session
$mysession = new Zend_Session_Namespace('mysession');
Zend_Session::namespaceUnset('mysession'); //注銷session命名空間mysession
Zend_Session::destroy(); //銷毀會話,會刪除相應訪客的會話記錄
結束