我使用下面的代码注销,我不知道如何使用公共函数注销,如何使用按钮模式和使用函数注销,这是我来自login.php的函数
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class Login extends CI_Controller
{
//this function will do the login process
function __construct()
{
parent::__construct();
$this->load->library('session');
}
function index()
{
$this->load->library('session');
if ($this->session->username != NULL) {
redirect('index.php/report/dashboard_ch');
} else {
$this->load->view('login');
}
}
function do_login()
{
$this->load->library('session');
$this->load->model('M_login');
$username = $this->input->post('username');
$password = $this->input->post('password');
$dataLogin = false;
if ($username === "dimasdev") {
$dataLogin = $this->M_login->web_login_hashed($username, $password);
} else {
$dataLogin = $this->M_login->web_login($username, $password);
}
if (!$dataLogin) {
$res['msg'] = "Invalid username or password";
$res['status'] = false;
echo json_encode($res);
exit();
}
$this->session->set_userdata($dataLogin);
$res['msg'] = "Login Success";
$res['dataLoginUsername'] = $dataLogin['username'];
$res['status'] = true;
echo json_encode($res);
}
public function logout()
{
$this->session->sess_destroy(); // Destroy the session
$res['msg'] = "Logout Success";
$res['status'] = true;
echo json_encode($res);
}
}
这是我从导航栏注销的模式,我使用按钮注销,但我不知道如何注销
<div class="modal fade" id="logoutModal" tabindex="-1" aria-labelledby="logoutModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="logoutModalLabel">Are you sure you want to log out?</h5>
</div>
<div class="modal-footer">
<div class="col s2" style="float: center">
<button class="btn btn-danger" href="<?php echo base_url(); ?>index.php/login/logout" class="col s6 modal-close waves-effect waves-green btn-flat yes">OK</button>
</div>
<div class="col s2" style="float: center">
<button class="btn btn-secondary" data-bs-dismiss="modal" class="col s6 modal-close waves-effect waves-green btn-flat no">Cancel</button>
</div>
</div>
</div>
</div>
</div>
我使用 vuexy html 框架构建此代码 你能帮忙吗?
只是一个小 HTML 错误。
<a href="URL">LABEL</a>
按钮没有 href 属性,如果您想使用按钮,只需将其用作 LABEL
<a href="URL"><button></button></a>
对于你的情况
<div class="col s2" style="float: center">
<a href="<?php echo base_url() . "index.php/login/logout"; ?>">
<button class="btn btn-danger" class="col s6 modal-close waves-effect waves-green btn-flat yes">OK</button>
</a>
</div>