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]
  • #1 / Oct 26, 2008 3:24pm

    Thorpe Obazee

    1138 posts

    I am having quite a problem with the $this->session->sess_destroy()

    When I use it, I can still echo the session variable. Here’s what my code looks like. I am using CI 1.7

    $this->session->sess_destroy();
            $this->session->set_flashdata('message', $this->lang->line('user_logged_out'));
            redirect('classifieds');
  • #2 / Oct 26, 2008 3:40pm

    Thorpe Obazee

    1138 posts

    ok.. I just tested the others and found out that the other logout routines are now not working on my app since the upgrade to 1.7.

  • #3 / Oct 26, 2008 3:43pm

    Thorpe Obazee

    1138 posts

    The temporary fix I did was to unset_userdata first before the destroy. although I doubt that the destroy worked.

    // --------------------------------------------------------------------
    
        /**
        * @desc Logging  out action for the application
        * 
        * @access public
        */
        public function logout()
        {
            $this->session->unset_userdata('username');
            $this->session->unset_userdata('first_name');
            $this->session->unset_userdata('last_name');
            $this->session->unset_userdata('role');
            $this->session->sess_destroy();
            $this->session->set_flashdata('message', $this->lang->line('user_logged_out'));
            redirect('classifieds');
        } // End logout
  • #4 / Oct 26, 2008 4:08pm

    Genki1

    44 posts

    Yes, we are having the same problem. In the library Session.php, destroying a session only deals with the cookie; it doesn’t deal with the session variables.

  • #5 / Oct 27, 2008 4:18am

    nizsmo

    41 posts

    sess_destroy() is working fine for me with the session data stored in the database 😊 For me calling the sess_destroy will actually delete the session database entry completely. Not sure why its not working for you guys?

  • #6 / Oct 29, 2008 4:33am

    Genki1

    44 posts

    Please give an example of a reliable technique for determining whether or not the user’s session is active.

    Thank you

  • #7 / Oct 29, 2008 8:45pm

    Thorpe Obazee

    1138 posts

    sess_destroy() is working fine for me with the session data stored in the database 😊 For me calling the sess_destroy will actually delete the session database entry completely. Not sure why its not working for you guys?

    I am not using any database to store the session.

    I might use the database for storing sessions. Will be converting on the weekends.

  • #8 / Nov 07, 2008 1:35pm

    RogerM

    21 posts

    I am using a database to hold sessions.
    I also have set 2 userdata variables.
    When I call sess_destroy, it deletes the record in the database, but I am still able to echo my userdata.

    My temporary fix is to use session->unset_userdata().

    Any thoughts?

  • #9 / Nov 07, 2008 5:42pm

    bapobap

    73 posts

  • #10 / Nov 09, 2008 12:42pm

    Thorpe Obazee

    1138 posts

    I am using a database to hold sessions.
    I also have set 2 userdata variables.
    When I call sess_destroy, it deletes the record in the database, but I am still able to echo my userdata.

    My temporary fix is to use session->unset_userdata().

    Any thoughts?

    I guess we are having the same issue.

  • #11 / Nov 09, 2008 3:41pm

    RogerM

    21 posts

    I guess so….

    I couldn’t find a bug report on it. I wonder if they know about it.

  • #12 / Dec 04, 2008 11:57pm

    pioSko

    12 posts

    I had the same thing. I managed to destroy it and have my user logout by adding

    $this->output->set_header("Cache-Control: no-cache");
    $this->output->set_header("Pragma: nocache");

    to my controllers… so now they look like this:

    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 😛

  • #13 / Dec 27, 2009 5:11pm

    seige

    1 posts

    pioSko’s solution worked great for me.

  • #14 / Dec 28, 2009 9:05pm

    ebollens

    1 posts

    Any reason not to just go with handing the user a new session?

    $this->session->sess_create();
  • #15 / Jun 05, 2010 11:31am

    Namaless

    14 posts

    This work’s for me:

    public function logout()
    {
        $this->session->sess_destroy();
        $this->session->sess_create();
            
        $this->session->set_flashdata('success', "LOGOUT OK.");        
        redirect();
    }
.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases