sess_destroy () It does not work in codeigniter

0

Excellent night, I hope you can help me, when I send my function call to destroy the session, it is not destroyed and it is still active if I try to enter 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 send the function from my view as follows:

<header>
    <nav>
        <a href="<?=site_url('login/logout') ?>">Salir</a>
    </nav>
</header>
    
asked by Rodrigo Arenas 07.12.2017 в 01:38
source

1 answer

1
if (!$this->session->userdata('login')) {
    redirect(base_url());
}

Validate if the session is open from the constructor of each controller.

With this validation if the user is not with the session open it will make a redirect at the beginning, at least I solved it in this way, greetings.

    
answered by 08.05.2018 / 21:31
source