我是codeigniter的初學者。從Here學習代碼。現在我需要某人幫助繼續session。爲什麼我得到這個Codeigniter會話錯誤
//config.php
<pre> <code>
$config['sess_driver'] = 'database';
$config['sess_save_path'] = 'ci_sessions';
$config['sess_cookie_name'] = 'cisessions';
$config['sess_expiration'] = 7200;
$config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = FALSE;
</code> </pre>
//數據庫表
CREATE TABLE IF NOT EXISTS `ci_sessions` (
`session_id` varchar(80) NOT NULL,
`ip_address` varchar(45) NOT NULL,
`user_agent` varchar(120) NOT NULL,
`last_activity` int(10) unsigned DEFAULT 0 NOT NULL,
`user_data` text,
KEY `last_activity` (`last_activity`)
);
mode_user
class Model_user extends MY_Model{
protected $_table_name = 'user';
protected $_order_by = 'name';
public $rules = array(
'email' => array('field' => 'email', 'label' => 'Email', 'rules' => 'trim|required|valid_email|xss_clean'),
'password' => array('field' => 'password', 'label' => 'Password', 'rules' => 'trim|required'),
);
function __construct(){
parent::__construct();
}
public function login(){
$user = $this->get_by(array(
'email' => $this->input->post('email'),
'password' => $this->hash($this->input->post('password')),
), TRUE);
if(count($user)){
$data = array(
'name' => $user->name,
'email' => $user->email,
'id' => $user->id,
'loggedin' => TRUE,
);
$this->session->set_userdata($data);
}
}
public function logout(){
$this->session->sess_destroy();
}
public function loggedin(){
return (bool) $this->session->userdata('loggedin');
}
public function hash($string){
return hash('sha512'. $string . config_item('encryption_key'));
}
}
用戶控制器
class User extends Backend_Controller{
function __consrtuct(){
parent::__consrtuct();
}
public function login(){
$rules = $this->model_user->rules;
$this->form_validation->set_rules($rules);
if($this->form_validation->run() == TRUE){
//login & redirect
$this->model_user->login();
}
$this->data['subview'] = 'admin/user/login';
$this->load->view('admin/_layout_modal', $this->data);
}
}
得到錯誤這樣
A PHP Error was encountered
Severity: Warning
Message: Unknown: Failed to write session data (user). Please verify that the current setting of session.save_path is correct (ci_sessions)
Filename: Unknown
Line Number: 0
Backtrace:
請指導我解決這個錯誤
感謝
將會話保存到數據庫的任何理由? –
@AbdullaNilam:很久以後你怎麼樣? – devpro
@devpro精細。更換名字。多數民衆贊成你不會注意到我 –