Welcome Guest, Not a member yet? Register   Sign In
CI 1.7 Session destroy
#11

[eluser]RogerM[/eluser]
I guess so....

I couldn't find a bug report on it. I wonder if they know about it.
#12

[eluser]pioSko[/eluser]
I had the same thing. I managed to destroy it and have my user logout by adding
Code:
$this->output->set_header("Cache-Control: no-cache");
$this->output->set_header("Pragma: nocache");

to my controllers... so now they look like this:

Code:
class Logout extends Controller {

    function Logout(){
        parent::Controller();
        $this->output->set_header("Cache-Control: no-cache");
        $this->output->set_header("Pragma: nocache");
    }
    
    function index(){
        $array = array('id' => NULL, 'logged_in' => FALSE);
        $this->session->unset_userdata($array);
        $this->session->sess_destroy();
        redirect('', 'refresh');
    }
}

Hope it helps.. feedback please. I may be doing it wrong Tongue
#13

[eluser]Unknown[/eluser]
pioSko's solution worked great for me.
#14

[eluser]Unknown[/eluser]
Any reason not to just go with handing the user a new session?

Code:
$this->session->sess_create();
#15

[eluser]Namaless[/eluser]
This work's for me:
Code:
public function logout()
{
    $this->session->sess_destroy();
    $this->session->sess_create();
        
    $this->session->set_flashdata('success', "LOGOUT OK.");        
    redirect();
}
#16

[eluser]GPSTrackit[/eluser]
I am using version 1.7.2 and I am having the same problem but the fix recommended is NOT working.

When a user logs in they see a simple page. My logout function looks like this:

Code:
function logout()
{
    $this->session->sess_destroy();
    $this->session->sess_create();
    $this->session->set_flashdata(array('message' => array('type' => 'success', 'content' => 'You have successfully logged out.')));    
    redirect("/");
}

When the user is redirect, the flashdata is gone and I am getting an error trying to display it. If I comment out just the sess_destroy or just the sess_create I still get an error and lose the flashdata. If I comment out both I get the flashdata but the session is not gone. I also tried adding $this->session->unset_userdata('variablename'); and still leave the destroy and create lines commented out and it kills my flashdata. The unset is unsetting a COMPLETELY unrelated value. Why is unset_userdata KILLING my flashdata?

It seems that CI really introduced a MAJOR bug in session handling. It might be important to note that I am using cookies and not the db option. I will try that next, but I'd like to stay away from the database. I am not fond of cookies either but it doesn't appear that there is a *reliable* native PHP session handler for CI, sadly.

Thank you to those that have some solutions to offer. Haters need not reply.
#17

[eluser]WanWizard[/eluser]
Your code works perfectly here, with database sessions. So there is nothing wrong with it.

Do you have this with all browsers? Did you check which headers are send to the browser? Any Ajax calls going to the same site simultaneously?

I'm pretty sure unset_userdata() isn't killing your flash data, the issue is probably that it's not send to the browser, redirects are notoriously unreliable when it comes to cookie sessions, some browsers ignore the HTTP headers completely when they see a header redirect.
#18

[eluser]GPSTrackit[/eluser]
Yeah it's a problem on all browsers. Like I said, if I turn off the unset_userdata and sess_destroy it DOES pass the flashdata. I am not sure how that's a browser issue.

I tried turning on the use_database and I got the same results. So it's not a cookie thing as far as I can tell.

Thanks for helping!
#19

[eluser]WanWizard[/eluser]
The code for cookie based sessions and database based sessions in this respect is identical. The only difference is that the flash data is in the cookie instead of the database.

Like I said, if I cut and paste your code into one of my controllers, it works without problems. Use firefox' live HTTP headers to check what is actually send to the browser when this code is processed. Disable cookie encryption so you can see what's happening.
#20

[eluser]Unknown[/eluser]
Destroy Session
[1] Core PHP
setcookie("ci_session", "", time()-60, "/", "",0);

[2] DB Session
$this->db_session->sess_destroy();

[3] Cookies
$this->load->helper('cookie');
delete_cookie("ci_session");




Theme © iAndrew 2016 - Forum software by © MyBB