[eluser]bloodagar[/eluser]
Update: Got it resolved! I changed
Code:
$this->db->get('users')
to
Code:
$this->db->get('users')->result_array()
in the if condition. Yay!
Quote:Also I got another problem, whatever I type in the username/password inputs it allows me to view the secure area. Here's the code:
the model
Code:
<?php
class MLogin extends Model {
function MLogin()
{
parent::Model();
}
function login($user, $pass)
{
$this->db->where('username', $user);
$this->db->where('password', $pass);
if ($this->db->get('users')) {
$this->session->set_userdata('logged_in', TRUE);
return TRUE;
} else {
return FALSE;
}
}
function logged_in()
{
if ($this->session->userdata('logged_in')==TRUE) {
return TRUE;
} else {
return FALSE;
}
}
}
?>
the controller
Code:
<?php
class Login extends Controller {
function Login()
{
parent::Controller();
$this->load->scaffolding('users');
$this->load->helper('url');
$this->load->helper('form');
$this->load->model('mlogin');
}
function index()
{
$data['error'] = "";
$user = $this->input->post('username');
$pass = $this->input->post('password');
if ($user) {
if ($this->mlogin->login($user, $pass)) {
redirect('login/secure', 'refresh');
} else {
$data['error'] = "Incorrect username/password";
$this->load->view('login', $data);
}
} else {
$this->load->view('login', $data);
}
}
function secure()
{
if ($this->mlogin->logged_in()) {
$this->load->view('secure');
} else {
redirect('login', 'refresh');
}
}
}
?>
I'd also appreciate of you guys have any suggestion/comments about my codes. Thank you very much!