phpcodeignitersessionlogout

Logout Link not working


So I am trying to click a logout link and end the session, and it doesnt seem to be working.

Link is located here: application -> views-> modules -> header.php like looks like this:

<a href="../admin/logout">Logout</a>

in the admin controller I have the function:

public function logout()
{
    $this->session->unset_userdata('logged_in');
    session_destroy();
    redirect('admin', 'refresh');
}

My routes files for admin look like this:

$route['admin/(:any)'] = 'admin/view/$1';
$route['admin'] = 'admin';

Admin views folder is located: views -> admin

Question: When I click on my logout link it does nothing. Like in my admin if there is no session it gets redirected to a login screen. That works but when I log out if it was redirecting to the admin page which is suppose to redirect to the login page if there is no session why is nothing happening?


Solution

  • $route['admin/(:any)'] = 'admin/view/$1';

    This code is redirecting admin/logout to admin/view/logout

    So, like you said, adding $route['admin/logout'] = 'admin/logout'; near the top of your routes should take you to the correct page