[eluser]Azraf[/eluser]
Hi,
I'm complete new in CI and need your advise/help in 2 field. This post contain the first one.
1. I've to implement session for Login into database and also need to setup a cookie for the remember me check box.
Code:
function loginCheck ()
{
$id = $this->input->post('id', true);
$uName = $this->input->post('a_name', true);
$password = $this->input->post('password', true);
$this->load->model($this->config->item('loginCheck'),'Login_model',TRUE);
$result = $this->Login_model->loginCheck($uName, $password);
if ($result)
{
$newdata = array(
'user_id' => $result->a_id,
'logged_in' => TRUE
);
$this->session->set_userdata($newdata);
$rem_me=$this->input->post('remember_me',true);
if ($rem_me==true)
{
$this->load->helper('cookie');
$bhr_cookie = array(
'name' => 'bhr_cookie',
'logged_in' => TRUE,
//set for 7 days
'expire' => '604800',
'domain' => 'myDomain.com',
'path' => 'directoryPath/',
'prefix' => 'login_',
);
set_cookie($bhr_cookie);
}
// $this->load->view('person/personList');
redirect('person/index');
}
else
{
$data= array();
$data['mainContent'] = "Your Login username / password does not match. Please try again.";
$data['homeTitle'] = 'Welcome';
$this->load->view('v-login',$data);
}
}
And in my Login model:
Code:
function loginCheck($uName,$password)
{
$this->db->select ( '*' );
$this->db->from ( 'ci_user_admin' );
$this->db->where ( 'a_name', $uName );
$this->db->where ( 'password', md5 ( $password ) );
$resultSet = $this->db->get ();
return $resultSet->row ();
}
And for authentication verification, I've use in other controller:
Code:
if (($this->session->userdata('logged_in') != TRUE)|| empty($_COOKIE['bhr_cookie']))
{
redirect('login/logout');
}
Again, I'm complete new to CI, and also learning php, therefore i know I'm doing it as novice, and am here to learn something from you.
N.B. My script was working fine before I try the remember me (cookie), with session in database. But after I try to combine the session with database and cookie both, I cant handle it. Therefore, need help from you.