I want to use Session data as a condition for a query in database, but it only returns NULL. I have tried $this->session->userdata('account'), but it still won't work.
Function - Login/Set Userdata :
public function login_auth()
{
$this->load->helper('security');
$this->form_validation->set_rules('username', 'Username', 'trim|required|xss_clean');
$this->form_validation->set_rules('password', 'Password', 'trim|required|xss_clean');
if ($this->form_validation->run() == FALSE) {
if(isset($this->session->userdata['logged_in'])){
$this->dashboard();
}else{
$this->index();
}
} else {
$data = array(
'username' => $this->input->post('username'),
'password' => $this->input->post('password')
);
$result = $this->agent_model->login($data);
if ($result == TRUE) {
$username = $this->input->post('username');
$result = $this->agent_model->read_user_information($username);
if ($result != false) {
$session_data = array(
'username' => $result[0]->username,
'owner' => $result[0]->owner,
'account' => $result[0]->account,
'id' => $result[0]->id
);
$this->session->set_userdata('logged_in', $session_data);
$this->dashboard();
}
} else {
$data = array(
'error_message' => 'Invalid Username or Password'
);
$this->load->view('header');
$this->load->view('pages/login', $data);
$this->load->view('footer');
}
}
}
Function - Using Userdata->Account as a condition(From Another Function)
$sess_account = $this->session->userdata('account');
var_dump($this->session->userdata('account'));
$coords = $this->map_model->get_coordinates($sess_account);
Am i missing something here? Any help is truly appreciated. Thank you!