大家好我有兩個網站在codeigniter開發。這些網站是完全不同的,但用戶的mdoel類似於登錄方法,因爲我認爲要回收該代碼。 問題是:如果我登錄到一個站點並打開另一個站點內的其他站點的用戶登錄到我的數據庫中不存在的其他站點。 數據庫是不同的,我不知道是什麼問題,或者如果我必須將我的登錄方法更改爲我的模型或某種配置。Codeigniter會話不同的網站
這是我的模型方法:
function login($username = '', $password = '') {
$user_name = base64_decode($username);
$password = base64_decode($password);
//Make sure login info was sent
if($username == '' || $password == '') {
return FALSE;
}
//Check if already logged in
if($this->session->userdata('username') == $username && $this->session->userdata('logged_in')) {
//User is already logged in.
return TRUE;
}
//Check against user table
$this->db->where('username', $user_name);
$this->db->where('password', $this->encrypt->sha1($password));
$this->db->where('active', 1);
$query = $this->db->get_where($this->user_table);
if ($query->num_rows() > 0) {
$row = $query->row_array();
//Destroy old session
$this->session->sess_destroy();
//Create a fresh, brand new session
$this->session->sess_create();
//Update Last Login
$data = array(
'last_login' => date('Y-m-d H:i:s')
);
$this->db->where('id', $row['id']);
$this->db->update($this->user_table, $data);
//Set session data
$this->session->set_userdata(array('id' => $row['id'], 'username' => $row['username'],'name' => $row['name'], 'surname' => $row['surname'], 'language' => $row['language']));
if ($row['type']==1){
//se è 1 è un administrator
$this->session->set_userdata(array('is_admin' => 1));
}
else{
$this->session->set_userdata(array('is_admin' => 0));
}
//Set logged_in to true
$this->session->set_userdata(array('logged_in' => TRUE));
//image profile
$this->db->where('user_id', $row['id']);
$query2 = $this->db->get_where('user_image_profile');
if ($query2->num_rows() > 0) {
$row_image = $query2->row_array();
$this->session->set_userdata(array('img_profile' => $row_image['filename']));
}
//Login was successful
return TRUE;
} else {
//No database result found
return FALSE;
}
}
都在同一域中運行這兩個網站? – 2013-05-08 07:17:22
是的,因爲在我的演示服務器 – 2013-05-08 07:40:47
Sharif Ul Islam的解決方案是否有效? – 2013-05-08 12:19:04