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.