Pergunta

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?

Foi útil?

Solução

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

Outras dicas

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');
}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top