我有一个回调函数来检查我的登录详细信息是否正确 - 如果它们错误,它会返回一个错误(这工作正常)。如果详细信息正确,则应设置会话$this->session->set_userdata('logged_in',TRUE);
,然后继续使用该功能login
并重定向到仪表板 - 此重定向工作正常。
在我function index(){}
的任何仪表板页面上都有这条线
if($this->session->userdata('logged_in')) redirect('dashboard/home');
上面的行是导致我的 310 重定向的行,但我不确定为什么?
我想检查用户是否登录重定向到dashboard/home
否则返回登录页面home/login
控制器:
class Home extends CI_Controller {
function __construct() {
parent::__construct();
}
public function index()
{
//if($this->session->userdata('logged_in')) redirect('dashboard/home');
$data['contentMangement'] = $this->options_model->systemOptions();
$data['pageTitle'] = 'Login';
$data['message'] = "";
$this->load->view('_assets/header', $data);
$this->load->view('login', $data);
$this->load->view('_assets/footer');
}
public function login() {
$this->form_validation->set_rules('userEmail','Username', 'required|valid_email|trim|max_length[99]|xss_clean');
$this->form_validation->set_rules('userPassword','Password', 'required|trim|max_length[200]|xss_clean|callback__checkUsernamePassword');
if($this->form_validation->run() === FALSE) {
$data['contentMangement'] = $this->options_model->systemOptions();
$data['pageTitle'] = 'Login';
$data['message'] = validation_errors('<div class="alert alert-error">', '</div>');
$this->load->view('_assets/header', $data);
$this->load->view('login', $data);
$this->load->view('_assets/footer');
}elseif($this->form_validation->run() === TRUE){
redirect('dashboard/home');
}
}
function _checkUsernamePassword() {
$username = $this->input->post('userEmail');
$password = $this->input->post('userPassword');
$user = $this->user_model->check_login($username,$password);
if(! $user)
{
$this->form_validation->set_message('_checkUsernamePassword', 'Sorry the details you provided have not been found');
return FALSE;
}else{
$this->session->set_userdata('logged_in',TRUE);
return TRUE;
}
}
}