iNET Interactive - Online Advertising Agency
          
   Home    Authors    About    Login    Contact Us
   Search:   
Advanced Search     
  Articles

  ASP (26)
  ASP.NET (19)
  C and C++ (4)
  CFML (2)
  CGI and Perl (16)
  Flash (2)
  Java (7)
  JavaScript (28)
  PHP (92)
  MySQL (13)
  MSSQL (3)
  HTML (35)
  SEO (9)
  Visual Basic (12)
  CSS (13)
  SSI (5)
  XML (12)
  C# (14)

  Developer News

July 20, 2008
Wiki: A Solution to the Web Design Problem
About
 
July 19, 2008
Top 10 Social Networking Sites
About
 
July 19, 2008
Plurk or Twitter: Which one is Better?
About
 
July 19, 2008
Create Menus with Lists and CSS
About
 
July 17, 2008
Poll: What do you do when you can't design?
About
 
July 17, 2008
22 Reasons to Plurk
About
 
Courtesy of moreover.com
 
Want to receive new articles via e-mail? Click here!
/Home /ASP

How many users are currently surfing your site? 

  Views:    3516
  Votes:    4
by Romeo Marquez 12/12/03 Rating: 

Synopsis:

Lately, a lot of websites show you how many users are currently surfing that site. I like that feature and maybe you like it to!
Pages: 
The Article

Here’s a tutorial to include that nice little feature to your nice little site!

 

There are several ways to accomplish this, but the easiest is with the help of global.asa

In case you do not know what global.asa is, I’ll explain it to you.

 

The global.asa file is a root-level file that can contain variables, objects or methods that are

available to every single ASP file in your application.

Therefore, you can declare a variable in global.asa and then ask for it in whatever.asp and

use it without needing anything else!

 

So, by using global.asa, we will keep count of how many users are active in our site.

 

Here’s the code for global.asa, this code will not be placed inside the <%%> tags

 

<SCRIPT LANGUAGE="VBScript" RUNAT="Server">

Sub Application_OnStart

                Application("CountActiveUsers") = 0 ‘ We initialize the counter

End Sub

 

Sub Session_OnStart

   Session.Timeout = 20 ‘ Session timeout determines how long will the server consider and idle

          ‘ session as an active session, it’s given in minutes.

   Session("Start") = Now

   Application.Lock

                Application("CountActiveUsers") = Application("CountActiveUsers") + 1 ‘The actual counter

   Application.UnLock

End Sub

 

Sub Session_OnEnd

   Application.Lock

Application("CountActiveUsers") = Application("CountActiveUsers") – 1’ Substract inactive users

   Application.UnLock

End Sub

</SCRIPT>

 

Place the global.asa in your root and then create whatever.asp and place the following code:

 

<html>

<head>

<title>How many users are active?</title>

</head>

<body>

 

Right now, there are <%= Application("CountActiveUsers")%> users surfing mysite.com

 

</body>

</html>

 

If you’re hosting your own site you might need to restart your IIS, if your hosting somewhere else,

there might be the need to ask the admin to restart your site.

 

Questions?

Write me, Romeo Marquez Guzman romeo@gelattina.com

www.gelattina.com 

 

 

Pages: 

Similar/related articles:


 
  Sponsors