Solved

capture closing event of a browser, then execute ASP code

Posted on 2004-08-17
5
203 Views
Last Modified: 2008-03-10
I have this page where a user logs in and I tag in the database that is he is logged. I use cookies (session when cookies are disabled) to log the user in and the tag in the database is simply a "restriction". I need this feature because only one user should be allowed to log in at a time, and his account cannot be used by the others from different PC. So, when another user logs in the same account, and this account is tagged as logged in in the db, he won't be allowed to enter the site.

The thing is,  when the logged user closes his browser window without logging out, the tag in the database as loggedin won't be reset. Therefore, the next time he logs in, he won't be allowed to since he's tagged in the database. I can't use Session_OnEnd because it's not fired by my server.

I'm looking into capturing the closing event of the browser window then, but I'm clueless about how to implement this. A lot suggested I used body onUnLoad in js but this is always raised when I change pages -- and I just want to capture the closing event. Once I captured it then I will run the ASP code where the user will be tagged as logged out in the database.

Any idea how I'd go about this problem?
0
Comment
Question by:ludy
5 Comments
 
LVL 46

Assisted Solution

by:fritz_the_blank
fritz_the_blank earned 50 total points
Comment Utility
I am afraid that the onUnLoad() makes no distinction between navigating to another page, using the x to quit, alt-f4, menu exit and etc. So essentially it is of no use (even if you put it in a frame so you can capture when the site is left).

The only thing that you can do is to make an entry into the database each time that a page is visited, and then you can assume that 20 minutes after the last entry, the session has expired.

FtB
0
 
LVL 9

Expert Comment

by:leechoonhwee
Comment Utility
Use global.asa

<SCRIPT LANGUAGE=VBScript RUNAT=Server>
Sub Session_OnEnd
'Add your Session_OnEnd code here
End Sub
</SCRIPT>
0
 
LVL 5

Expert Comment

by:LlamaJoe
Comment Utility
I have done very similar work by using application variables, rather than session variables, as the session would not be accessible by the user logging in on another pc, but the application variables would.

The general sense, in session_onStart check an application variable (make it an array, or custom object, or whatever - it doesn't have to be a string) and store the status of all logged in users -  make sure that the session_onEnd event removes the user from the object - then if a user tries to log in from another machine, it will say that you are already logged in, so wait until the session is available - if it is the same user trying to log in, ask for credentials, and then delete the other instance of the user in the application variable - you will have to include a piece of code on every page to check to make sure that the current user is still valid in the application variable.

or, move to .net and use security pricipals..... enjoy!
0
 

Author Comment

by:ludy
Comment Utility
I can't use global.asa because session_onend isn't fired up. :-(
0
 
LVL 26

Accepted Solution

by:
Rejojohny earned 50 total points
Comment Utility
ur problem would not anyway get solved by getting "closing" event .. what happens if the user's browser crashes or he moves to another site in the same window? Better would be to have an application varibale with the current user list and the last page logged accessed time .. this can be updated everytime the user accesses a particular page .. so if the user does not "logout" and closes the browser, the next time he tries to access the applicaiton within 20 minutes, he would still be present in the application variable and so would be rejected a new connection .. lets say u decide on 20 minutes as the timeout period .. so after 20 minutes when he tries to access the applicaiton again, he would still be there in the applicaiton variable but as 20 minutes has passed, his request would be processed ...
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now