ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

CI 1.7 Session destroy

October 26, 2008 3:24pm

Subscribe [10]
  • #16 / Nov 03, 2010 2:50pm

    GPSTrackit

    3 posts

    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:

    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 / Nov 03, 2010 3:59pm

    WanWizard

    4475 posts

    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 / Nov 03, 2010 6:04pm

    GPSTrackit

    3 posts

    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 / Nov 03, 2010 6:44pm

    WanWizard

    4475 posts

    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 / Feb 13, 2011 6:44am

    Manoj kumar

    1 posts

    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”);

  • #21 / Dec 06, 2011 9:01am

    electronic

    1 posts

      I’m a new to codeigniter. so please guide me. I have member controller which has login, logout, registration functionlity.

    issues :

      1.first time am coming to browser and logged in, redirected to account controller. but session is not setting properly. but second time login, session setted properly. while clicking any link goes to login page.
     
      I don’t know what issues please help me.

      codeigniter version 1.7.2.

  • #22 / Dec 06, 2011 9:36pm

    luffy152

    1 posts

    thank you

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases