1

i have some problem, my codes is working normally, but the session is not. here the codes :

public function index()
{
    if (isset($_POST['btnSubmit'])) {
        $this->lm->username = $_POST['username'];
        $this->lm->password = $_POST['password'];
        $sql = sprintf("SELECT hakAkses, nip FROM user WHERE username = '%s' AND password = '%s'",
              $this->lm->username,
              $this->lm->password
              );
        $query = $this->db->query($sql);
        $row = $query->row();
        $sessData = array('nip' => $row->nip,
                          'hakAkses' => $row->hakAkses);
        $this->session->set_userdata($sessData);
        print_r($this->session->all_userdata());

        if ($this->session->userdata('hakAkses') == 'ADMIN') {
            redirect('Admin/index','refresh');
        } else if ($this->session->userdata('hakAkses') == 'PENGAJAR'){         
            redirect('Pengajar/index','refresh');
        } else {
            redirect('Login','refresh');
        }
    } else {
        $this->load->view('Login/LoginView');
    }

}

That went well when i did it after set the session$this->session->set_userdata($sessData);. But when i try print again in other form the session has gone.

my session config :

$config['sess_driver'] = 'database';
$config['sess_cookie_name'] = 'ci_sessios';
$config['sess_expiration'] = 7200;
$config['sess_save_path'] = 'ci_sessions';
$config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = FALSE;

OK the reason is everytime i redirect page the session generate new session. how to handle this?

1 Answers1

0

From your code it's not clear why . But possibly u forgot to load session from the other page . So Try auto load session library from autoload.php. Or use $this->load->library('session'); in the controller.

Jayakrishnan
  • 1,295
  • 2
  • 13
  • 27