简体   繁体   English

Codeigniter自动加载会话不起作用

[英]Codeigniter autoload session is not working

the problem is this, when i login into the project, it creates the session, but when i try to acces the session from other controller, or even from the same controller, the session data doesn't existe, i have loaded session from autoload, and i also tried loading the session in the constructor, but the issue is still there. 问题是,当我登录到项目时,它会创建会话,但是当我尝试从其他控制器甚至从同一控制器访问该会话时,该会话数据不存在,我已经从自动加载中加载了会话,并且我还尝试在构造函数中加载会话,但问题仍然存在。 forgive for my english, this is not my native language, i hope you can help me please, thanks 原谅我的英语,这不是我的母语,希望您能帮助我,谢谢

Controller login function: 控制器登录功能:

public function do_login(){
        $user = $this->input->post('usuario');
        $passwd = $this->input->post('clave');
        $data = $this->login_model->do_login($user,$passwd);

        if($data){
            $this->session->set_userdata("login",(array)$data); 
            //print_r($this->session->userdata());
            echo json_encode(array('status' => 1,'message'=>'Bienvenido','idPerfil'=> $data->idPerfil));
        }else
            echo json_encode(array('status' => 0,'message'=>'Usuario o contraseña incorrecto'));
    }

constructor
public function __construct(){
        parent::__construct();

        $this->load->model('login_model');
        $this->load->library('Mobile_Detect');
        //$this->load->model('cat_usuarios_model');
    //  $this->load->model('cat_sucursales_model');
    $this->load->library("session");

    }  

this is the autoload.php line 这是autoload.php行

$autoload['libraries'] = array('session','database','form_validation','email');

Your problem is with configuration. 您的问题与配置有关。

$config['sess_save_path'] = NULL

This is causing the failure. 这导致了故障。

If $config['sess_driver'] = 'files'; 如果$config['sess_driver'] = 'files'; then $config['sess_save_path'] must be set to an absolute path to the folder where the files will be saved. 然后必须将 $config['sess_save_path'] 设置为保存文件的文件夹的绝对路径

You can create a folder for the files. 您可以为文件创建一个文件夹。 See the documentation for more information . 有关更多信息,请参见文档 Or, you can use the following. 或者,您可以使用以下内容。

$config['sess_save_path'] = sys_get_temp_dir();

It is probably better to create a specific folder to save session files than to use sys_get_temp_dir() . 创建一个特定的文件夹来保存会话文件可能比使用sys_get_temp_dir() It is a tiny bit more work because setting permissions and ownership of the folder can be tricky if you just learning how to do those things. 这还需要一点点工作,因为如果您只是学习如何做,则设置文件夹的权限和所有权可能会很棘手。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM