php 7 上的 ion auth codeigniter 不工作

ion auth codeigniter on php 7 not working

我创建了一个名为 'Basic' 的库,并在该库中调用了 'ion auth' 库来检查用户登录。 它在 php 5 上运行,但是当应用程序 运行 在 php 7 上时,用户无法登录应用程序。我正在检查 php 上的会话数据是否为空 7. 怎么了?

我的 'Basic.php' 图书馆:

public function check_login(){
    //ajax request
    if ($this->_ci->input->is_ajax_request()) {
        if (!$this->_ci->ion_auth->logged_in())
        {
            if($this->is_pjax()){
                die('<script>alert("Anda belum login atau sesi login anda sudah habis, silahkan melakukan login ulang.");window.location.replace("'.base_url().'");</script>');
            }else{
                die(json_encode(array('status'=>false,'noty'=>'Anda belum login atau sesi login anda sudah habis, silahkan melakukan login ulang.')));
            }

        }else{
            $user_data=$this->_ci->ion_auth->user()->row();
            $user_data->grup=$this->_ci->ion_auth->get_users_groups()->row()->name;
            return $user_data;
        }
    }else{
        if (!$this->_ci->ion_auth->logged_in())
        {
            // redirect them to the login page
            redirect('login', 'refresh');
        }
        else
        {   
            $user_data=$this->_ci->ion_auth->user()->row();
            $user_data->grup=$this->_ci->ion_auth->get_users_groups()->row()->name;
            return $user_data;
        }
    }
}

我的 'Auth' 控制器处理登录:

    public function login()
{

    if ($this->ion_auth->logged_in())
    {
        $this->index();
    }

    $this->form_validation->set_rules('email', str_replace(':', '', $this->lang->line('login_identity_email')), 'required|valid_email');
    $this->form_validation->set_rules('password', str_replace(':', '', $this->lang->line('login_password_label')), 'required');


    //ajax request
    if ($this->input->is_ajax_request()) {


        if(!$this->basic->is_pjax()){

            header('Access-Control-Allow-Origin: *');

            $res=array('status'=>false,'noty'=>'Login Gagal !');
            //sleep(10);
            $post=$this->input->post(null,true);

            if ($this->form_validation->run() == true)
            {
                if ($this->ion_auth->login($post['email'], $post['password'], false))
                {
                    $this->session->set_flashdata('message', $this->ion_auth->messages());
                    $res=array('status'=>true,'noty'=>'Login Berhasil !');
                }
            }else{
                $res['noty']=(validation_errors()) ? validation_errors() : $this->session->flashdata('message');
            }

            die(json_encode($res));
        }else{

            $this->data['title'] = $this->lang->line('login_heading');

            if ($this->form_validation->run() == true)
            {
                // check to see if the user is logging in
                // check for "remember me"
                $remember = (bool) $this->input->post('remember');

                if ($this->ion_auth->login($this->input->post('email'), $this->input->post('password'), $remember))
                {
                    $user_data=$this->ion_auth->user()->row();

                    $grupname=$this->ion_auth->get_users_groups($user_data->id)->row()->name;



                    //if the login is successful
                    //redirect them back to the home page
                    $this->session->set_flashdata('message', $this->ion_auth->messages());
                    if (!$this->ion_auth->is_admin()) // remove this elseif if you want to enable this for non-admins
                    {
                        // redirect them to the home page because they must be an administrator to view this
                        //redirect('/', 'refresh');
                        die('<script>window.location.replace("'.base_url().'dashboard");</script>');
                    }
                    else
                    {
                        die('<script>window.location.replace("'.base_url().'admin/dashboard");</script>');
                        //redirect('admin/dashboard', 'refresh');
                    }

                }
                else
                {
                    // if the login was un-successful
                    // redirect them back to the login page
                    $this->session->set_flashdata('message', $this->ion_auth->errors());
                    $this->login_view();
                    ///redirect('login', 'refresh'); // use redirects instead of loading views for compatibility with MY_Controller libraries
                }
            }
            else
            {
                // the user is not logging in so display the login page
                // set the flash data error message if there is one
                $this->login_view();

            }
        }
    }else{
        $this->login_view();
    }
}

我在每个控制器上添加了这段代码来检查用户登录:

$this->data['user_data']=$this->basic->check_login();

我对这个库有同样的问题: * 姓名:离子授权 *版本:2.5.2 *作者:本埃德蒙兹 PHP 7

基本上我在函数的最后一个参数中发现了问题:登录。

如果记住参数设置为 0 则不起作用如果设置为 1 则有效!

所以在你的代码中试试这个:

改变

if ($this->ion_auth->login($post['email'], $post['password'], false))

if ($this->ion_auth->login($post['email'], $post['password'], true))