代码点火器会话管理-刷新登录页面,而不是填充会话



我是Code Igniter的新手,我继承了一个内置的网站,在从PHP 5.6迁移到7.2时,该网站停止工作,我不得不升级。我认为会话管理在2.0x和3.0.0版本之间发生了很大变化(我已经转到了3.0.0版本(。我想使用文件来存储会话,并配置了一个sess_path,但当我的用户尝试登录时,页面只会刷新-这表明下面控制器代码中的if($this->form_validation->run((==FALSE(:语句总是true,这很奇怪,就好像我没有填写用户名或密码并提交一样,表单验证会运行。

public function index(){
$this->load->library('session');
if ($this->session->userdata('user_is_admin')) {
redirect('admin/login/welcome');
}
$this->load->library('form_validation');
$this->form_validation->set_error_delimiters('<span class="form-error">', '</span>');
$this->form_validation->set_rules('username', 'Username','required');
$this->form_validation->set_rules('password', 'Password','required');
if ($this->form_validation->run() == FALSE):

$data['title'] = 'login';
$data['content'] = 'admin/login/index-view';
$this->load->view('template-admin-login',$data);
else:
$this->db->where('user_is_admin',1);
$this->db->where('user_activated',1);
$this->db->where('user_published',1);
$this->db->where('user_email',$this->input->post('username'));
$this->db->where('user_password', md5($this->input->post('password')));
$query = $this->db->get('user')->row();
if(!empty($query)):
$newdata = array(
'user_id'  => $query->user_id,
'user_name'  => $query->user_name,
'user_is_admin'  => $query->user_is_admin
);
$this->session->set_userdata($newdata);
$this->session->set_flashdata('message_welcome', 'Hi '.ucfirst($this->session->userdata('user_name')).'!');
redirect('admin/login/welcome');
else:
$this->session->set_flashdata('message_red', 'Username or password incorrect.');
redirect('admin/login');
endif;
endif;

配置文件包含会话配置的以下内容:

$config['sess_driver']          = 'files';
$config['sess_cookie_name']     = 'ci_session';
$config['sess_expiration']      = 7200;
$config['sess_save_path']       = BASEPATH . 'application/cache/';
$config['sess_use_database']    = FALSE;
$config['sess_table_name']      = 'ci_sessions';
$config['sess_match_ip']        = FALSE;
$config['sess_time_to_update']  = 300;

表单非常简单——一个用户名和密码字段以及提交按钮,它会发布到admin/login页面。已经运行了会话管理的Code Igniter指令,但不知道为什么页面只是刷新。希望我不用从头开始重写整件事。感谢您的帮助!

我认为保存路径不是您想要的。BASEPATH指向系统目录。这将指向/application中的/cache目录。

$config['sess_save_path'] = APPPATH . 'cache/';

最新更新