Sign Out

I have a logout controller in codeigniter:

<?php class Logout extends MY_Controller { function index() { $this->session->sess_destroy(); redirect('index.php'); } } 

This puts me out of the system, but when I call another controller after logging, for example "/ site / addnewpost", it again misleads me, as if the invasion had not been destroyed before. Why is this happening?

+6
source share
5 answers

Follow the ALex recommendations, but using the CI code :). What I mean, try to parse each session information separately. I read once about the problem in version 2.0.3, I think, but now I donโ€™t remember, and I donโ€™t have time to look for the link. This is on their forum, however, and the same thing: unset each element of the session one after another.

 $this->session->unset_userdata('data_one'); $this->session->unset_userdata('data_two'); $this->session->unset_userdata('data_three'); $this->session->unset_userdata('data_one'); $this->session->sess_destroy(); redirect('home','refresh'); // <!-- note that //you should specify the controller(/method) name here 

You need to redirect because a CI session is just cookies, not a native array of php sessions.

One more thing ... make sure the error is not in your login methods, which logs you in whether or not you log out successfully!

+11
source

Try explicitly deleting these items:

 $this->Session->delete('User'); $this->Session->destroy(); $this->Cookie->delete("User"); $this->Cookie->destroy(); $this->Auth->logout(); $this->redirect('whereever'); 
+2
source

My problem is with server side caching. The fastest thing I could fix was add random text to the exit link:

 <?php $this->load->helper('string'); echo anchor('/home/logout/'.random_string(), 'logout'); ?> 

home / logout contains the same code as function index in the question.

Just to let you know that redirect('/', 'refresh') doesn't work for me, but I did a quick test again.

I assume that the random_string() method can be replaced by the output of headers that force the cache to be cleared, etc. As you probably guessed, I canโ€™t do it right now, because Iโ€™m very busy. Maybe later.

+1
source

You can also try manually setting your "logged_in" or whatever you called a session to false. Then, destroying all other session data.

  $this->session->set_userdata('logged_in', FALSE); $this->session->session_destroy(); redirect('index'); 
+1
source

first we need to load the session library to work with the session, than disconnect the sessionID and destroy the session. I use this code to cancel a session and log out securely.

 $this->load->library('session'); $this->session->set_userdata('user_id', FALSE); $this->session->sess_destroy(); $this->load->view('your URL'); 
0
source

Source: https://habr.com/ru/post/904388/


All Articles