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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can restrict the number of concurrent users?

Status
Not open for further replies.

bunnyweb

MIS
Jan 13, 2003
42
IE
Hi Everyone.

I have a web application and I want to limit it so only a set number of concurrent users can access the pages at the same time.

I want to allow the first 5 people that access the application to use it with no problem. But then when the 6th person attempts to access the application they get an error message. But I want it to be dynamic, so if one person leaves the pages then another person can go on.

Would I have to use a login screen to accomplish this? How else would I keep track of someone logging in and loggin out? I would much rather not use a login screen if I can avoid it.

I hope this makes sense! Any advice and/or suggestions would be greatly appreciated. Thanks in advance!
 
You can store vlaues such as the number of users currently logged on by setting a vlaue in the global.asa file. e.g.
Code:
Sub Session_OnStart
	'Insert script to be executed when a session starts
	' Set online users number each time someone logs on
	Application.Lock
        		Application("WhoOn") = Application("WhoOn") + 1
    	Application.Unlock
End Sub

Sub Session_OnEnd
	'Insert script to be executed when a session ends
	' Set online users number each time someone logs off
    	Application.Lock
    		Application("WhoOn") = Application("WhoOn") - 1
    	Application.Unlock
End Sub
This will however only say how many users are currently "in session" and a session may last the default of 20 (I think it is 20 anyway) minutes if the user stays there but is inactive.

For more info try looking for more examples of using the global.asa file as it can be quite handy for issues such as yours.

----------------------------------------------------------------------

Need help finding an answer?

Try the search facilty ( or read FAQ222-2244 on how to get better results.
 
Thank you, this is exactly what I needed. However, I have a problem with it.

Everything works great with adding users. Every time a new user accesses the web page the Application("WhoOn") variable adds 1.

And when I use a log-out button that calls Session.Abandon the Application("WhoOn") variables substracts 1.

BUT, when the user simply closes their browser window instead of clicking on the log-out button and Session.Adandon isn't called, the Application("WhoOn") variable does not decrease by 1. It is almost as if the Session_OnEnd subroutine is not being called when the browser window closes.

Am I doing something wrong? Any suggestions?
 
Yes that is a slight problem...basically unless the sub is called "properly" then this function doesn't get called.

One option is to have a window that is called from each page if the user closes their browser (like some annoying sites that pop up loads when you close their window!). Hopefully you could do it in a slightly less annoying way and just pop up a tiny window saying "Thank you...you are now logged out." and call session.abandon in this window.

----------------------------------------------------------------------

Need help finding an answer?

Try the search facilty ( or read FAQ222-2244 on how to get better results.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top