[eluser]dennismonsewicz[/eluser]
I have written my admin portion of my site and for some reason calling the $this->session->sess_destroy() method does not work... I have to physically tell my code to unset the data I have in the session before it will work.
Any idea as to why this would happen?
My Auth Library
Code:
<?php
Class Auth {
var $CI;
function Auth() {
$this->CI =& get_instance();
$this->CI->load->database();
}
function process_login($login = NULL) {
if(!isset($login))
return FALSE;
if(count($login) != 2)
return FALSE;
$username = $login[0];
$password = md5($login[1]);
$query = $this->CI->db->get_where('users', array('username' => $username, 'password' => $password));
$results = $query->result();
if($query->num_rows() == 1) {
$this->CI->session->set_userdata('username', $username);
$this->CI->session->set_userdata('is_admin', $results[0]->is_admin);
return TRUE;
} else {
return FALSE;
}
}
function logged_in() {
if($this->CI->session->userdata('username') == false) return false;
else return true;
}
function restrict($logged_out = false) {
if($logged_out && $this->logged_in())
redirec('/admin/main/index');
if(!$logged_out && !$this->logged_in()) {
redirect('/admin/login');
}
}
}
Login#logout Controller
Code:
<?php
class Login extends Controller {
function Login() {
parent::Controller();
}
function index() {
if(!$this->auth->logged_in()) {
$this->session->set_flashdata("message", popup_msg("Please Login Below"));
$this->load->view('admin/login_view');
} else {
redirect('/admin/main/index');
}
}
function authorize() {
if($this->input->post('_login') == '1') {
$login = array($this->input->post('username'), $this->input->post('password'));
if($this->auth->process_login($login)) {
redirect('/admin/main/index');
} else {
redirect('/admin/login');
}
}
}
function logout() {
// $this->session->unset_userdata('username');
// $this->session->unset_userdata('is_admin');
$this->session->sess_destroy();
$this->session->set_flashdata("message", popup_msg("You have logged out"));
redirect('/admin/login');
}
}
?>
For some reason the code just keeps redirecting to /admin/main/index instead of going back to the login screen