Part of the EllisLab Network
   
 
closing sessions on browser exit
Posted: 16 March 2006 05:29 PM   [ Ignore ]  
Summer Student
Total Posts:  20
Joined  02-28-2006

CI sessions appear to remain active if the client restarts his browser. How can I change this behavior?

Profile
 
 
Posted: 23 March 2006 12:34 PM   [ Ignore ]   [ # 1 ]  
Summer Student
Total Posts:  20
Joined  02-28-2006

Giving this one a bump.

Anybody have some suggestions?

Profile
 
 
Posted: 23 March 2006 01:15 PM   [ Ignore ]   [ # 2 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  152
Joined  03-02-2006

Sessions are just cookies with expire times.  Closing the browser does not actually “end” a session.. You may be able to set a smaller timeout?

 Signature 

Charles Cox (just call me Chuck cheese  )
“Hey.. where is everyone??”

Profile
 
 
Posted: 23 March 2006 01:34 PM   [ Ignore ]   [ # 3 ]  
Summer Student
Total Posts:  20
Joined  02-28-2006

Ahh, right. I am used to working with php sessions that get destroyed on browser exits.

Is there a way emulate that behavior for cookies? javascript?

Profile
 
 
Posted: 23 March 2006 02:10 PM   [ Ignore ]   [ # 4 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  886
Joined  03-06-2006

Check the documentation on the Session Class, under the paragraph Saving Session Data to Database. It implies that if you kill the session in the database it will also destroy the cookie. If so, that would be a good approach.

 Signature 

Corozal, Belize | Linux.bz | Using Kubuntu Linux 7.10 | CodeIgniter 1.5.3

Profile
 
 
Posted: 23 March 2006 02:51 PM   [ Ignore ]   [ # 5 ]  
Summer Student
Total Posts:  20
Joined  02-28-2006
linuxbz - 23 March 2006 02:10 PM

Check the documentation on the Session Class, under the paragraph Saving Session Data to Database. It implies that if you kill the session in the database it will also destroy the cookie. If so, that would be a good approach.

but this would need to happen when the browser exits. still not sure how to do that…

Profile
 
 
Posted: 23 March 2006 02:52 PM   [ Ignore ]   [ # 6 ]  
Grad Student
Rank
Total Posts:  52
Joined  03-21-2006

If no expiration date is specified, the cookie will expire when the browser is closed.

Profile
 
 
Posted: 23 March 2006 03:05 PM   [ Ignore ]   [ # 7 ]  
Summer Student
Total Posts:  20
Joined  02-28-2006
pbreit - 23 March 2006 02:52 PM

If no expiration date is specified, the cookie will expire when the browser is closed.

So if I set sess_expiration to 0 then manually do timeouts based on last_activity in my sessions db with something like this:

$this->db->use_table('ci_sessions');
$conditions = array('session_id' => $this->session->userdata('session_id'),
    
'ip_address' => $this->session->userdata('ip_address'),
    
'user_agent' => $this->session->userdata('user_agent'));
$this->db->where($conditions);
$query = $this->db->get();
$row = $query->row();
if (
$row->logged_in) {//user has valid session
    
$now = time();
    
$idle = $now - $row->last_activity;
    if (
$idle > 36000) //timeout after 10 minutes of inactivity
        
$this->logout();
...

I should be good to go?

Profile
 
 
   
 
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 819, on March 11, 2010 11:15 AM
Total Registered Members: 120577 Total Logged-in Users: 29
Total Topics: 126616 Total Anonymous Users: 2
Total Replies: 665627 Total Guests: 322
Total Posts: 792243    
Members ( View Memberlist )