dseslyh6662605 2016-10-08 12:28
浏览 44

重定向后CodeIgniter会话丢失

I have a project that use CI 3 I developed on localhost in Windows using XAMPP, and final product was deployed on Debian Apache server. I tried to logged in but it's redirected back to default controller.

I tried to enter the wrong login and it's show the error correctly, but when I entered the right login it keeps comeback to my login controller.

Here is my login controller (Auth.php) :

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Auth extends CI_Controller {
public function __construct(){
    parent::__construct();
    $this->load->model('user_m');
    if ($this->session->userdata('akses') == 'admin') {
        redirect('dashboard');
    }
    elseif ($this->session->userdata('akses')=='user') {
        redirect('user');
    }
}
public function index() {
    $this->load->view('login_v');

}

public function login() {
    $nip=$this->input->post('nip');
    $password=$this->input->post('password');

    $query = $this->user_m->login($nip);
    if ($query->num_rows()==1)
    {
        $row = $query->row();
        if ($password == $this->bcrypt->check_password($password,$row->password)) {    
            $data_login= array(
            'nip'=>$row->nip,
            'id_pegawai'=>$row->id_pegawai,
            'akses'=>$row->akses
            );
            echo $this->session->set_userdata($data_login);
            $akses = $this->session->userdata('akses');
            if ($akses=='admin') {
                redirect('dashboard');
            }
            elseif ($akses=='user') {
                redirect('user');
            }       
        }
        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>";
         }
    }
}
?>

Can anyone help me?

UPDATE

When I checked the session after redirect, it always pass a null value with new id session. Even I tried the native session class still didn't help it.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 测距传感器数据手册i2c
    • ¥15 RPA正常跑,cmd输入cookies跑不出来
    • ¥15 求帮我调试一下freefem代码
    • ¥15 matlab代码解决,怎么运行
    • ¥15 R语言Rstudio突然无法启动
    • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
    • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
    • ¥15 用windows做服务的同志有吗
    • ¥60 求一个简单的网页(标签-安全|关键词-上传)
    • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法