ASP – An open application environment, it enables powerful server-side scripting.  Home Web Programming ASP Show the Number of Users Online
Your Ad Here

Show the Number of Users Online


Show the Number of Users OnlineLearn how to use global.asa to display the number of users visiting your site. This tutorial can be broken down into two sections, global.asa, and numvis.asp. Before you can begin this tutorial, make sure your host supports global.asa.

GLOBAL.ASA
Global.asa is defined as an optional file that defines functions, variables, and methods that are accessible by every ASP page within the application.The global.asa file is often used to define and proccess session-specific variables, which is its function in this tutorial. Global.asa can not be written in ASP, so no <% %> tags in this file, here's the file:

<script language="vbscript" runat="server">
Sub Application_OnStart
Application("numvis")=0
End Sub
Sub Session_OnStart
Application.Lock
Application("numvis")=Application("numvis") + 1
Application.UnLock
End Sub
Sub Session_OnEnd
Application.Lock
Application("numvis")=Application("numvis") - 1
Application.UnLock
End Sub
</script>

English: whenever a user visits the site (triggering a session, Session_OnStart), the server adds one to the number of users, and whenever that user leaves (ending the session Session_OnEnd), the server subtracts one from the number of users. Application_OnStart applies only to when the server is started.

NUMVIS.ASP
This file will display the number of visitors online like so:

<html>
<head><title>Spoono Rocks!</title>

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

Thats it! Put that code into your site or let it stand alone, and you'll be able to see how many visitors are at your site.

Author's URL: Wilfried Schobeiri
Thank you for voting.
Rate this Materials:
Bad 
1 2 3 4 5 Excellent
print this page subscribe to newsletter subscribe to rss

Web programming � everything from the basics of visual design and architecture to the specifics of applications, graphics, and scripting. More Web Programming: Most Popular Materials | Fresh Materials | More ASP Tutorials at LearnPHP.org

Add comments to "Show the Number of Users Online"

Only registered users can write comment

Reader's comments