سؤال

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?

هل كانت مفيدة؟

المحلول

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

نصائح أخرى

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');
}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top