I'm trying to make a login system using codeigniter but there is a fatal error found when trying to login :(
<?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
}
<?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
}
?>
The problem is you have two class with same name Auth
one for controller and one for model.One script cannot contain two class that's why you got that error.
Rename your auth model like this Auth_model.php and declare class like this
class Auth_model extends CI_Model
Hope you can do rest how to use this model.