I'm trying to make a login system using codeigniter but there is a fatal error found when trying to login :(
Controler Auth.php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
function __construct(){
parent::__construct();
$this->load->model('Auth/login','',TRUE);
}
class Auth extends CI_Controller {
public function index()
{
// $this->load->view('Home');
}
// start login
public function login()
{
$this->load->helper(array('form'));
$this->load->view('Login');
}
// end login
// start logout
public function logout()
{
$this->session->unset_userdata('logged_in');
redirect('Login','refresh');
}
// end logout
// start checkLogin
public function checkLogin()
{
// field validation successfull, validate against database
$username = $this->input->post('username');
$password = $this->input->post('password');
// query database
$this->load->model('Auth');
$result = $this->Auth->login($username, $password);
if ($result) {
$sess_array = array();
foreach ($result as $row) {
$sess_array = array(
$id = $row->id,
$username = $row->username
);
$this->session->set_userdata('logged_in',$sess_array);
}
return TRUE;
}else {
$this->form_validation->set_message('checkLogin', 'Invalid username or password');
return FALSE;
}
}
// end checkLogin
}
Models Auth.php
<?php
class Auth extends CI_Model
{
// start login
function login($username, $password)
{
$this->db->select('id','username','password');
$this->db->from('user_details');
$this->db->where('username', $username);
$this->db->where('password', $password);
$this->db->limit(1);
$query = $this->db->get();
if ($query->num_rows() == 1) {
return $query->result();
}else{
return false;
}
}
// end login
}
?>