我真的是CodeIgniter
的新手。我的代码有问题,我通过Vue
用Axios创建了一个登录系统。会话已成功设置,但仍然不允许我访问管理页面,我使用Ajax
从视图发送数据,并且已在控制器上成功接收到数据。
登录过程已成功运行,并且我为此创建了一个会话,当我向后退回Vue
时,该会话已成功读取,但是当我将页面切换到管理页面时,该会话不可读并将页面重定向到登录页面,我的代码怎么了?
$uname = $this->input->post('username');
$upass = $this->input->post('password');
$utype = $this->input->post('types');
$where = array('user'=>$uname, 'pass'=>md5($upass), 'type'=>$utype);
$check = $this->Login_models->login_check("user", $where)->num_rows(); //account checking
$type = $this->Login_models->check_user_identity($utype)->row_array(); //user check, admin or student
if ($check > 0) {
$this->_result['error'] = FALSE;
if($type['type'] == 'admin'){
$data_session = array('nama'=>$uname, 'status'=>"admin");
$this->session->set_userdata($data_session);
$this->_result['type'] = 'admin';
}
else if($type['type'] == 'student'){
$data_session1 = array('nama'=>$uname, 'status'=>"student");
$this->session->set_userdata($data_session1);
$this->_result['type'] = 'student';
}
}else{
$this->_result['error'] = TRUE;
$this->_result['message'] = array(
'no_account' => 'Account not found'
);
}
}
echo json_encode($this->_result);