Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

session decrement on browser closing

Status
Not open for further replies.

SBGibson

Programmer
Apr 18, 2001
125
IT
Maybe you've answered many times to this question.
I've to decrement the number of users connected to my site when a user close the browser (waiting for session timeout takes too long time).
I tried opening a small .asp window on the onunload event but it happens every time I refresh the page, I click on a link and so on, it's annoying.
I tried a onunload=document.write('<img src=&quot;logout.asp&quot;>') but he write the image instead of going to the other page.
I tried checking the opened property of the window, but it's always true.
You have some idea about how to decrement that session? How to load a page undergound without opening a window or in some other way?
Thanx in advance. Stevie B. Gibson
 
You should create file Global.asa and save (upload) it in the root directory of you site.

Simple code of this file looks like this:
----------------------------------------------------
<script language=&quot;vbscript&quot; runat=&quot;server&quot;>
Sub Application_OnStart
'some code
End Sub

Sub Application_OnEnd
'some code
End Sub

Sub Session_OnStart
'some code
End Sub

Sub Session_OnEnd
'some code
End Sub
</script>
----------------------------------------------------

If you can see there are 4 main events, we now need Session_OnStart and Session_OnEnd. Put there some code to keep number of visitors.

Sub Session_OnStart
Application(&quot;currentUsers&quot;) = Application(&quot;currentUsers&quot;) + 1 'we'll keep number of users in the variable with the Application scope

End Sub

Sub Session_OnEnd
Application(&quot;currentUsers&quot;) = Application(&quot;currentUsers&quot;) - 1 'decrement visitors

End Sub




Was this what you needed?
Good Luck! :)
 
No.

Session_OnEnd occurs when the session timeouts, after 20 minutes depending on the configuration, and not when thhe user close the browser.

I need to decrement the counter when the user close the browser.
Stevie B. Gibson
 
Stevie, you are not right!

Session_OnEnd occurs when the user ends its session, which can be either by
1) closing browser OR
2) when session timeouts OR
3) by calling Session.Abandon() method!!! Check it!
Good Luck! :)
 
you can change the timeout time of the session...

Code:
Session.Timeout=1  '1 minute
www.vzio.com
ASP WEB DEVELOPMENT



 
if I change the timeout the user will be logged out if he do nothing for a minute. (I use session also for the login-logout with password of the user).

I'm sorry Eugene but I'm sure that closing browser windows don't fire the Onend event. It's due to the desync property of the http protocol.
The closing of the browser don't fire server events. Check it...I'm pretty sure about it :) Stevie B. Gibson
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top