[eluser]Unknown[/eluser]
I am taking a stab at CI, and I have hit a bit of a wall. I created a user login function in my user controller, and it works dandy right up until I navigate away from the landing after sucessfully authenticating. My sessions disapear.
I will be using sessions to secure pages, so if your session user id value is not populated then you will be redirected to log in. Anyhow here is what I have.
Code:
function login()
{
$this->load->library('validation');
$this->load->helper('url');
$this->load->library('session');
if($_POST['username'])
{
$this->load->database();
$query = $this->db->query("SELECT * FROM users WHERE username = '".$_POST['username']."' and password = '".md5($_POST['password'])."'");
if($query->num_rows() > 0){
//return true;
$status = "0";
foreach ($query->result() as $row)
{
$username = $row->username;
$id = $row->id;
}
$sid = array('id' => $id);
$this->session->set_userdata($sid);
$data['goodz'] = $this->session->userdata('id');
$data['status'] = $status;
}
else {
$status = "1";
$data['status'] = $status;
$data['goodz'] = $this->session->userdata('id');
}
}
$this->load->view('login_vals',$data);
}