Hi , I m new to codeigniter and i m trying to build a login system. However the logout system is not working well. After I click logout in /main/home it shows URL error. anyone know whats the problem ?
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class main extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->helper('url');
$this->load->helper('form');
session_start();
}
public function index()
{
$this->login();
}
public function login()
{
$this->load->view('login');
}
public function home()
{
$this->load->view('home');
}
public function denied()
{
$this->load->view('denied');
}
public function logout()
{
$this->session->sess_destroy();
redirect('main/login');
}
public function login_validation()
{
$this->load->library('form_validation');
$this->form_validation->set_rules('username', 'Username', 'required|min_length[3]|max_length[12]');
$this->form_validation->set_rules('password', 'Password', 'required|sha1|callback_password_check');
if ($this->form_validation->run()){
$data = array(
'password' => $this->input ->post('password '),
'logged' => 1
);
$this->session->set_userdata($data);
redirect('main/home');
} else {
$this->load->view('login');
}
}
public function password_check()
{
$username = $this->input->post('username');
$password = $this->input->post('password');
$this->load->model('users');
if($this->users->log_in($username, $password)){
return True;
}else{
$this->form_validation->set_message('password_check','The username or password is not correct.');
return False;
}
}
public function checklogged()
{
if ($this->session->userdata('logged'))
{
}else{
redirect('main/denied');
}
}
}