You'll need a database that has the following columns in the table. (TrackID, TrackDate, Sessions) Then use the following to refer to your stats throughout your site:
<% = Application("ActiveUsers") %>
<% = Application("TotalSessions") %>
<% = Application("TodaySessions") %>
This is what the global.asa should look like: <SCRIPT LANGUAGE="VBScript" RUNAT="Server">
On Error Resume Next
Sub Application_OnStart Application("ActiveUsers") = 0 End Sub
Sub Session_OnStart Dim SQL Dim RS Dim oConn Dim TotalSessions Dim TodaySessions Dim DBDriver Dim DBPath Dim DBUser Dim DBPass
DBDriver = "Microsoft Access Driver (*.mdb)" DBPath = Server.Mappath("/ADIRECTORY/TOTHEDATABASE.mdb") DBUser = "" DBPass = ""
Set oConn = Server.CreateObject("ADODB.Connection") oConn.Open "DRIVER={" & DBDriver & "}; DBQ=" & DBPath, DBUser, DBPass
' Get total number of sessions for today SQL = "Select Sessions From Sessions Where TrackDate = #" & Date() & "#" Set RS = oConn.Execute(SQL)
' If no recorde for today was found, we need to add a new record ' and if a record was found, we increment the value and store ' it back to the database If RS.EOF Then NewTotal = 1 SQL = "Insert Into Sessions (TrackDate, Sessions) " SQL = SQL & "Values ('" & Date() & "', " & NewTotal & ")" Else NewTotal = CInt(RS("Sessions")) + 1 SQL = "Update Sessions Set Sessions = " & NewTotal & " " SQL = SQL & "Where TrackDate = #" & Date() & "#" End If
Set RS = Nothing
oConn.Execute(SQL)
' Get total number of session since database created SQL = "Select Sum(Sessions) As TotalSessions From Sessions" Set RS = oConn.Execute(SQL) TotalSessions = RS("TotalSessions") Set RS = Nothing
' Get total number of sessions for today SQL = "Select Sessions From Sessions " SQL = SQL & "Where TrackDate = #" & Date() & "#" Set RS = oConn.Execute(SQL) TodaySessions = RS("Sessions") Set RS = Nothing
oConn.Close Set oConn = Nothing
Session.Timeout = 5 Session("Start") = Now
' Assign all of my application variables Application.Lock Application("TotalSessions") = TotalSessions Application("TodaySessions") = TodaySessions Application("ActiveUsers") = Application("ActiveUsers") + 1 Application.Unlock End Sub
Sub Session_OnEnd ' Remove user who is no longer on site Application.Lock Application("ActiveUsers") = Application("ActiveUsers") - 1 Application.UnLock End Sub
</SCRIPT>
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |
More ASP Code Articles More By aspfree developerWorks - FREE Tools! | Learn to enable users to both rate existing animations and to combine existing animations into new snippets. This is the third in a series of three tutorials that chronicle the building of a site that enables collaborative discussion and animation building using Domino and OpenLaszlo. FREE! Go There Now!
| | | | Visit IBM developerWorks to download IBM DB2 Express-C 9.5, a no-charge version of DB2 Express 9 database server. DB2 Express-C offers the same core data server base features as other DB2 Express editions and provides a solid base to build and deploy applications developed using C/C++, Java, .NET, PHP, and other programming languages. FREE! Go There Now!
| | | | Analysts, architects, and developers who have existing COBOL or PL/I skills and want to extend those skills to deploy new workloads on the mainframe can use the IBM Enterprise Modernization Sandbox for System z to find hands-on walkthroughs of common real world scenarios. The scenarios provide examples of how to rapidly design, create, assemble, test, and deploy high-quality Web, Web services, portal, and SOA applications for IBM CICS, IBM IMS, and IBM WebSphere Application Server. FREE! Go There Now!
| | | | Learn how to implement a build management system that uses and extends your existing automation technologies. This tutorial shows, step-by-step, how to install and configure IBM Rational Build Forge to manage builds for Jakarta Tomcat from source code. FREE! Go There Now!
| | | | Listen to this webcast to get an overview of Info 2.0 and a technical demo of how to quickly build an enterprise mashup. IBM's Info 2.0 technology leverages emerging Web 2.0 technologies such as mashups, feeds, AJAX, and JSON in order to simplify assembly of information using feeds and services. Come learn about the technical elements of Info 2.0 including the Feed Generation framework, Mashup Engine, and mashup assembly components. Learn how to pull information from databases, departmental information, and the Web to create mashups critical to your company’s success. We will also discuss best practices to help you get started. FREE! Go There Now!
| | | | Regression testing -- in which code is thoroughly tested to ensure that changes have not produced unexpected results -- is an important part of any development process. But many testing environments neglect the terminal-based applications that still form the backbone of many industries. In this tutorial, you'll learn how the Rational Functional Tester Extension for Terminal-Based Applications works with other Rational Functional Tester to help test terminal-based applications quickly and easily. FREE! Go There Now!
| | | | Visit IBM developerWorks to try the IBM SOA Sandbox for process. The SOA Sandbox for process focuses on providing a trial environment with the necessary tooling and components required to gain a better understanding of business processes and how to best improve existing business processes to derive value quickly. FREE! Go There Now!
| | | | The Eclipse community is constantly working to extend Eclipse's functionality. In this webcast, learn about some of the most important and feature-rich projects under development. From multi-language support to plug-in development, tune in to see what Eclipse is capable of now. FREE! Go There Now!
| | | | IBM Lotus Notes 8 provides a wide range of developers the ability to provide customized, integrated user interfaces via composite applications and via custom sidebar and toolbar plug-ins. This webcast provides you with tips and techniques to use with out-of-the-box capabilities of Lotus Notes 8, and survey how you can share useful components within your own company and within a larger community. FREE! Go There Now!
| | | | Explore how Rational and WebSphere software enable enterprise documentation in SOA environments. Specifically, a new integration between IBM WebSphere® Business Modeler and IBM Rational® Method Composer software can help technical writers more easily keep enterprise operations manuals in sync with changes that are made to business processes, resulting in more accurate and timely documentation that benefits the entire enterprise. FREE! Go There Now!
| | | | All FREE IBM® developerWorks Tools! | |