Excellent night, I hope you can help me, when I call my function to destroy the session, it is not destroyed and it is still active if I try to enter through the URL.
my controller is the following, to start and of course here is the function to be able to destroy the session
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class login extends CI_Controller {
public function __constuct(){
parent::__construct();
}
public function index(){
if($this->session->userdata('username')){
redirect('admin');
}
if(isset($_POST['password'])){
$this->load->model('usuario_model');
if($this->usuario_model->login($_POST['username'],md5($_POST['password']))){
$this->session->set_userdata('username',$_POST['username']);
redirect('admin');
}else{
redirect('login');
}
}
$this->load->view('login');
}
public function logout(){
$this->session->sess_destroy();
redirect('login');
}
}
I command to fetch the function from my view as follows:
<header>
<nav>
<a href="<?=site_url('login/logout') ?>">Salir</a>
</nav>
</header>
Validates if
session
it is open from the constructor of each controller.With this validation, if the user is not with the
session
open one, he will do anredirect
at the beginning, at least I solved it this way, greetings.