• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Destroying a session

#1
[eluser]Ajaxian64[/eluser]
Hi All,

I set up for the very first time my web app to production server.
Every things work fine.

I use Chrome to observe the Session settings (cookies). I use cookies + ci database for storing session.
And I use CI "session" library

When I logout, I use this code
Code:
$this->session->sess_destroy();
However with Chrome, on my PC, I see the session always exists.

Do you know why ?
I would esperate to have nothing in my Chrome session viewer.... :-S

#2
[eluser]smilie[/eluser]
Hm, I believe there is _always_ a session present... sess_destroy() only destroys data you have added by set_userdata(). Following:
'session_id' => random hash,
'ip_address' => 'string - user IP address',
'user_agent' => 'string - user agent data',
'last_activity' => timestamp

Would be always accessible. At least, that is what I have noticed when I user sess_destroy.

Cheers,
Smilie

#3
[eluser]Ajaxian64[/eluser]
Thanks for your reply.

#4
[eluser]InsiteFX[/eluser]
Code:
$this->session->sess_destroy();
$this->userdata = array();

InsiteFX

#5
[eluser]Ajaxian64[/eluser]
is it the code to do for erasing completely the session ?
In the case it is, it would be valuable to introduce it in sess_destroy() (to encapsulate it inside)

#6
[eluser]InsiteFX[/eluser]
I just extend the CI session class and using MY_Session and add it in.
You could also try unset.

InsiteFX

#7
[eluser]Ajaxian64[/eluser]
thanks

#8
[eluser]InsiteFX[/eluser]
This is how I do it, change to what you need.
Code:
<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/**
* ------------------------------------------------------------------------
* CI Session Class Extension.
* ------------------------------------------------------------------------
*
* Add the following define to the bottom of application/config/constants.php
* // Define Ajax Request
* define('IS_AJAX', isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest');
*
*/

class MY_Session extends CI_Session {
   /*
    * Do not update an existing session on ajax calls
    *
    * @access    public
    * @return    void
    */
    public function sess_update()
    {
        if ( ! IS_AJAX)
        {
            $this->sess_time_to_update = 300;
            parent::sess_update();
        }
        else
        {
            $this->sess_time_to_update = 1200;
            parenet::sess_update();
        }
    }

    function sess_destroy()
    {
        parent::sess_destroy();

        $this->userdata = array();
    }

}

// ------------------------------------------------------------------------
/* End of file MY_Session.php */
/* Location: ./application/libraries/MY_Session.php */

InsiteFX


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.