Привет Всем, я спрашиваю, могу ли я решить эту проблему. проблема заключается в том, что после того, как я нажал кнопку «Назад» после выхода из системы, пользователь все еще может получить доступ к странице или набрав ссылку на страницу. я подумал, что если я смогу уничтожить сеанс, он автоматически отключит эти страницы ..
<?php defined('BASEPATH') OR exit('No direct script access allowed');
class Auth extends MY_Controller {
public function index(){
$this->data['page_title'] = "User Login";
$this->load->view('templates/master', $this->data);
}
public function login(){
$username = $_POST['username'];
$password = $_POST['password'];
$data = $this->User_model->login ($username, $password);
if($data){
$this->session->set_userdata('users', $data);
$session_data = array(
'username' => $username);
$this->session->set_userdata($session_data);
redirect('users');
}
else{
$this->session->set_flashdata
('loginfail','<div class="alert alert-danger"><a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>
<strong>Danger !</strong> Invalid Email or Password .</div>');
return redirect("auth");
}
}
public function logout()
{
$this->session->unset_userdata(array('username','id'));
$this->session->sess_destroy();
redirect('auth');
}
}
<a href="<?php echo ('auth/logout')?>" data-toggle="modal" data-target="#logoutModal">
<i class="fas fa-sign-out-alt fa-sm fa-fw mr-2 text-gray-400"></i>
Logout
</a>
Код контроллера моей домашней страницы
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Users extends MY_Controller {
function __construct() {
if(empty($this->session->userdata('id'))){
redirect('auth/logout');
}
}
public function index()
{
$this->data['page_title'] = "Users List";
$this->data['users'] = $this->User_model->get();
$this->load->view('templates/master', $this->data);
}
public function add()
{
$this->data['page_title'] = "Add User";
$input_data = $this->input->post();
if(!empty($input_data))
{
$this->User_model->insert($input_data);
redirect('/users');
} else {
$this->load->view('templates/master', $this->data);
}
}
public function edit($id)
{
$this->data['page_title'] = "Edit User";
$input_data = $this->input->post();
if(!empty($input_data)){
$this->User_model->update($input_data);
redirect('/users');
} else {
$this->data['users'] = $this->User_model->get($id);
$this->load->view('templates/master', $this->data);
}
}
public function delete($id)
{
$this->User_model->delete($id);
redirect('/users');
}
}
Код моего основного контроллера
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class MY_Controller extends CI_Controller {
protected $data;
public function __construct()
{
parent::__construct();
define('CONTROLLER', $this->router->fetch_class());
define('METHOD', $this->router->fetch_method());
}
}