473,396 Members | 2,076 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Count of current visitors

cc


From the popular website At this link:
http://www.w3schools.com/asp/asp_globalasa.asp

I got this code, but it does not work on my server... I can open three
IE browsers and watch the count go to three. Upon closing two, each
having separate sessions (and session ID's of course), the count
remains at three! I'm not looking for alternative ways of doing this:
I'm interested in knowing why the application variable does not get
reduced upon ending the session by closing the browser. Any ideas?

Thanks,
See below:

The Global.asa file:

<script language="vbscript" runat="server">
Sub Application_OnStart
Application("visitors")=0
End Sub

Sub Session_OnStart
Application.Lock
Application("visitors")=Application("visitors")+1
Application.UnLock
End Sub

Sub Session_OnEnd
Application.Lock
Application("visitors")=Application("visitors")-1
Application.UnLock
End Sub
</script>

To display the number of current visitors in an ASP file:

<html>
<head>
</head>
<body>
<p>
There are <%response.write(Application("visitors"))%>
online now!
</p>
</body>
</html>

Jul 19 '05 #1
5 3592
Did you refresh your 1° page after closing 2 and 3 ?
Jul 19 '05 #2
cc@cc.com wrote:
From the popular website At this link:
http://www.w3schools.com/asp/asp_globalasa.asp

I got this code, but it does not work on my server... I can open three
IE browsers and watch the count go to three. Upon closing two, each
having separate sessions (and session ID's of course), the count
remains at three! I'm not looking for alternative ways of doing this:
I'm interested in knowing why the application variable does not get
reduced upon ending the session by closing the browser. Any ideas?

This seems to be a very prevalent misconception.

The session does not end when the user closes his browser. Think about it.
How can the server know when a user closes his browser? Answer: it can't.
HTTP is a stateless protocol. There is no "signal" sent to the server when a
user closes his browser, or navigates to another website. The only way a web
server has of knowing a session is still in use is if it receives requests
for pages with the session ID in the request headers.

There are only two ways a session will end:

1. A Session.Abandon statement is executed
2. The session's timeout period is exceeded, i.e., the server receives no
new requests for pages containing that session id for a longer period of
time than the session's timeout setting.

So, in the scenario you describe above: if your session timeout setting is
at the default value of 20 min., the user count will get adjusted 20 min.
after the user closes his browser.

Aaron describes a way to get a more accurate count of current users using a
database in this article:
http://www.aspfaq.com/show.asp?id=2491

HTH,
Bob Barrows
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Jul 19 '05 #3
Sessions timeout after n minutes (default is 20 I think) so you'll
have to be patient (or change the setting)

cc@cc.com wrote in message news:<41***************@news.dallas.sbcglobal.net> ...
From the popular website At this link:
http://www.w3schools.com/asp/asp_globalasa.asp

I got this code, but it does not work on my server... I can open three
IE browsers and watch the count go to three. Upon closing two, each
having separate sessions (and session ID's of course), the count
remains at three! I'm not looking for alternative ways of doing this:
I'm interested in knowing why the application variable does not get
reduced upon ending the session by closing the browser. Any ideas?

Thanks,
See below:

The Global.asa file:

<script language="vbscript" runat="server">
Sub Application_OnStart
Application("visitors")=0
End Sub

Sub Session_OnStart
Application.Lock
Application("visitors")=Application("visitors")+1
Application.UnLock
End Sub

Sub Session_OnEnd
Application.Lock
Application("visitors")=Application("visitors")-1
Application.UnLock
End Sub
</script>

To display the number of current visitors in an ASP file:

<html>
<head>
</head>
<body>
<p>
There are <%response.write(Application("visitors"))%>
online now!
</p>
</body>
</html>

Jul 19 '05 #4
> > I got this code, but it does not work on my server... I can open three
IE browsers and watch the count go to three. Upon closing two, each
having separate sessions (and session ID's of course), the count
remains at three! I'm not looking for alternative ways of doing this:
I'm interested in knowing why the application variable does not get
reduced upon ending the session by closing the browser. Any ideas?

This seems to be a very prevalent misconception.

The session does not end when the user closes his browser. Think about it.
How can the server know when a user closes his browser? Answer: it can't.

True, and I think people get confused because if they do close a
browser window, then open a new one, they get a new session.
Jul 19 '05 #5
cc
On Mon, 2 Aug 2004 06:29:21 -0400, "Bob Barrows [MVP]"
<re******@NOyahoo.SPAMcom> wrote:

I've been developing on the IIS platform since '98, and I've never
needed this counter functionality before. And this caught me off
guard. OF COURSE! The browser isn't going to send a last http call
before the .exe ends, so the server won't know when it closes.

I could SWEAR I read in one of those WROX books that session ended on
closing the browser, and that kinda' stuck with me.

Anyway... what's a 20 minute delay in the scope of all the other stuff
we have to deal with.
cc@cc.com wrote:
From the popular website At this link:
http://www.w3schools.com/asp/asp_globalasa.asp

I got this code, but it does not work on my server... I can open three
IE browsers and watch the count go to three. Upon closing two, each
having separate sessions (and session ID's of course), the count
remains at three! I'm not looking for alternative ways of doing this:
I'm interested in knowing why the application variable does not get
reduced upon ending the session by closing the browser. Any ideas?

This seems to be a very prevalent misconception.

The session does not end when the user closes his browser. Think about it.
How can the server know when a user closes his browser? Answer: it can't.
HTTP is a stateless protocol. There is no "signal" sent to the server when a
user closes his browser, or navigates to another website. The only way a web
server has of knowing a session is still in use is if it receives requests
for pages with the session ID in the request headers.

There are only two ways a session will end:

1. A Session.Abandon statement is executed
2. The session's timeout period is exceeded, i.e., the server receives no
new requests for pages containing that session id for a longer period of
time than the session's timeout setting.

So, in the scenario you describe above: if your session timeout setting is
at the default value of 20 min., the user count will get adjusted 20 min.
after the user closes his browser.

Aaron describes a way to get a more accurate count of current users using a
database in this article:
http://www.aspfaq.com/show.asp?id=2491

HTH,
Bob Barrows
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"


Jul 19 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: deko | last post by:
Below are the contents file that has the IP address and time of visit of visitors to a website. 68.122.69.241|1089822686 68.122.69.241|1089823630 68.122.69.241|1089823638
5
by: toedipper | last post by:
Hello, I am developing a site using php and mysql and I would like to be able to let visitors know how many other visitors are currently browsing the site i.e. 'There are currently x amount of...
1
by: Greg Collins [InfoPath MVP] | last post by:
Is it possible to get a count of active visitors currently on your site?
0
by: lkrubner | last post by:
The idea I'm trying to get at is that I want the tag info for the tag "photography", and I want the date, and I want a count of any comments a tag may have. This following query gets back all the ...
6
by: Sjaakie | last post by:
Hi, Is HttpContext.Current.User unique for each visitor or is it shared across an application? Have some problems that might have to do with this and found contradictory answers on this...
4
by: Jofio | last post by:
I am developing a picture gallery - pictures of landscapes and various other subjects. My site has a left panel consisting of thumbnails of pictures which when clicked displays the corresponding...
18
by: damezumari | last post by:
I would like to know how many of the visitors to my site has js enabled and how many has it turned off. I haven't found a simple solution searching Google groups so I suggest the following using...
32
by: Ciaran | last post by:
Hi I've seen this a few places - The site lists off the number of people (not logged in) currently browsing the site. How can I do this with php / mySQL please?
1
by: dez5000 | last post by:
I'm trying to get a report by location that would list the number of visits to the location for the month but also count the number of unique visitors to that location. I have a table of data with...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.