tags:

views:

66

answers:

3

Django, Python: How do I know if users have closed their browser without click logout?

Really seriously question, because I need to analyse the user activities.

+2  A: 

HTTP is a stateless protocol: you can't know at the server if the user has simply closed their browser without informing you.

Ned Batchelder
A: 

It's not pretty, but you could fire off ajax requests with the user's session info (or some cookie, or any way of identifying the user) every x seconds with javascript and if you haven't received anything from that user in 2*x seconds, then they're likely to have left the page/site.

Davy8
+1  A: 

it something to not do , but you can do something similar to Gmail (the way that they track if a user is still connected or not) you can do an AJAX request each 10 second or so (max time that will take a page to be loaded so that you don't mistake changing page to disconnection) , this Ajax request is like a "i'm still here" when it's received by the view it reset a timer ( this timer have been initialized for each user from the beginning ) to 0 otherwise if this timer exceed 10 s , you can say that the user "is gone without disconnecting".

you can pull also another way using comet (reverse Ajax) lcheck Orbited.

by the way disconnecting can me more than one thing : click on a disconnect link, remove session cookies , close page ...

singularity
I think we can all agree this is something not to do.
Daniel Roseman