简体   繁体   English

重定向后Codeigniter会话无法保存

[英]Codeigniter Session can't save after redirect

I have a project that i developed using CodeIgniter on localhost in Windows using XAMPP. 我有一个使用XAMPP在Windows的localhost上使用CodeIgniter开发的项目。 This project is almost done and running well in my server and localhost on my first laptop (i developed on my first laptop). 这个项目几乎已经完成, 并且在我的第一台笔记本电脑(我在第一台笔记本电脑上开发)上的服务器和localhost中运行良好。 But, when i tried to running this project on my second laptop, this project is lost / remove the session when page loading / redirect. 但是,当我尝试在第二台笔记本电脑上运行该项目时,该项目丢失/在页面加载/重定向时删除会话。 Whereas the session data has been received and generated well before the page refresh/ redirect. 而会话数据已在页面刷新/重定向之前就已接收并生成。

Note: I use same source code on my first and second laptop 注意:我在第一台和第二台笔记本电脑上使用相同的源代码

I dont know why. 我不知道为什么。 I've tried the solution of problems in stackoverflow friends but dont get a work solution. 我已经尝试过在stackoverflow朋友中解决问题的方法,但是没有得到有效的解决方案。

My Autoload 我的自动加载

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

My Config session and cookie by default 默认情况下, 我的配置会话和cookie

$config['sess_driver'] = 'files';
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 7200;
$config['sess_save_path'] = NULL;
$config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = FALSE;

$config['cookie_prefix']    = '';
$config['cookie_domain']    = '';
$config['cookie_path']      = '/';
$config['cookie_secure']    = FALSE;
$config['cookie_httponly']  = FALSE;

My controller 我的控制器

public function auth()
{
    $username=$this->input->post('username');
    $password=$this->input->post('password');

    $this->login_m->set_username($username);
    $query = $this->login_m->login();
    if ($query->num_rows()==1)
    {
        $row = $query->row();
        if ($password == $this->bcrypt->check_password($password,$row->password)) {    
            $data_login= array(
            'username'=>$row->username,
            'id_user'=>$row->id_user,
            'nama'=>$row->nama,
            'akses'=>$row->akses
            );
            $this->session->set_userdata($data_login);
            $akses = $this->session->userdata('akses');
            if ($akses=='super admin' or $akses=='admin') {
                redirect('dashboard');
            }elseif ($akses=='user') {
                    redirect('home');
            }       
        }
        else {
            echo "<script>alert('Gagal login: Cek nip, password!');history.go(-1);</script>";
        }
    }
    else {
        echo "<script>alert('Gagal login: Cek nip, password!');history.go(-1);</script>";
    }
}

My Model 我的模特

public function login()
    {
        $query = "SELECT * from por_user where username = ?";
        return $this->db->query($query,array($this->get_username()));
    }

Note: I use same source code on my first and second laptop 注意:我在第一台和第二台笔记本电脑上使用相同的源代码

When i am print the session after redirect the result is null 当我在重定向后打印会话时,结果为null

Can anyone help me? 谁能帮我? pardon my english :D Thankyou 请原谅我的英语 :D Thankyou

You need to set save path something like 您需要设置保存路径,例如

application/cache/session/ 应用程序/缓存/会话/

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

Permission 0700 权限0700

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

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