开发者

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

开发者 https://www.devze.com 2023-01-22 21:43 出处:网络
Django, Python: How do I know if us开发者_如何学Pythoners have closed their browser without click logout?

Django, Python: How do I know if us开发者_如何学Pythoners have closed their browser without click logout?

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


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


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 ...


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消