I have a project that i developed using CodeIgniter on localhost in Windows using XAMPP. This project is almost done and running well in my server and localhost on my first laptop (i developed on my first laptop). 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.
My Autoload
$autoload['libraries'] = array('database','session','pagination','bcrypt','form_validation');
My Config session and cookie by default
$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
Can anyone help me? pardon my english :D Thankyou
You need to set save path something like
application/cache/session/
$config['sess_save_path'] = APPPATH . 'cache/session/';
Permission 0700
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.