Sonny G
Sonny G

Reputation: 1343

How to logout code igniter session without form

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?

Upvotes: 0

Views: 2888

Answers (2)

Vivek Pandey
Vivek Pandey

Reputation: 406

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');
}

Upvotes: 0

user3470953
user3470953

Reputation: 11335

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');
}

Upvotes: 1

Related Questions