Question

I have a login and logout view but I do not want a form to logout. How can I use a button to logout my session?

Was it helpful?

Solution

You can use a link because without form you cannot use button otherwise you have to use ajax

<a href="<?php echo base_url() ?>controller_class_name/logout">Logout</a>

function logout() {
    $this->session->sess_destroy();
    redirect('controller_class/login');
}

OTHER TIPS

You can target the controller logout method through html a tag, and in your controller method you can destroy the session of codeigniter then redirect to home page or login page.

<a href="<?php echo base_url() ?>controller/logout">Logout</a>

public static function logout() 
{
    $this->session->sess_destroy();
    redirect('controller/login');
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top