config\config.php 設定
$config['sess_driver'] = 'database';
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 7200;
$config['sess_save_path'] = NULL;
$config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = FALSE;
$config['sess_use_database'] = TRUE;
$config['sess_table_name'] = 'ci_sessions';
DB設定,使用mysql
CREATE TABLE `ci_sessions` (
`id` varchar(40) NOT NULL,
`ip_address` varchar(45) NOT NULL,
`timestamp` int(11) NOT NULL,
`data` blob NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
ALTER TABLE `ci_sessions`
ADD PRIMARY KEY (`id`), ADD KEY `ip_address` (`ip_address`);
controller 初始化
public function __construct()
{
parent::__construct();
$this->load->driver('session');
}
$this->session->userdata('item'); 讀取session
$this->session->set_userdata('some_name', 'some_value'); 設定session
$this->session->unset_userdata('some_name'); 刪除session
沒有留言:
張貼留言