0

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

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;

表单非常简单 - 用户名和密码字段和提交按钮,它发布到管理/登录页面。一直在运行用于会话管理的 Code Igniter 指令,但无法弄清楚为什么页面只是刷新。希望我不必从头开始重写整个事情。任何帮助都感激不尽!

4

1 回答 1

0

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

$config['sess_save_path'] = APPPATH . 'cache/';
于 2018-11-28T00:55:31.057 回答