ASP Code
  Home arrow ASP Code arrow Tracking Users, Page Views by the Day Exam...
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Dedicated Servers 
Actuate Whitepapers 
Moblin 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
ASP CODE

Tracking Users, Page Views by the Day Example
By: aspfree
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 3
    2000-03-20

    Table of Contents:

    Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    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

     

    IBM® developerWorks developerWorks - FREE Tools!


    NEW! BlammoSplat: Build a community Web site of OpenLaszlo animations, Part 3: The community animation

    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!


    NEW! Download DB2 Express-C 9.5

    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!


    NEW! IBM Enterprise Modernization Sandbox for System z: Architecture

    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!


    NEW! Improve your build process with IBM Rational Build Forge, Part 1: Create a continuous build and integration environment

    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!


    NEW! Info 2.0: Harnessing the power of Web 2.0 and Enterprise Mashups

    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!


    NEW! Test terminal-based applications with Rational Functional Tester

    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!


    NEW! Try the IBM SOA Sandbox for Process

    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!


    NEW! Webcast: Eclipse: Empowering the universal platform

    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!


    NEW! Webcast: Quickly provide customized, integrated user interfaces with Lotus Notes 8

    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!


    NEW! Whitepaper: Achieving consistency between business process models and operational guides

    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!

    ASP CODE ARTICLES

    - ASP Forms
    - ASP: The Beginning
    - Getting Remote Files With ASP Continued
    - Inbox and Outbox Manipulation in ASP
    - Relational DropDownList Using VB.NET
    - Ad Tracking URL Hits
    - Use ViewState to display one record per page...
    - Send Email using ASP.NET formatted in HTML
    - ASP File Explorer
    - ASP/XML Interview questions by Srivatsan Sri...
    - Various methods of setting Date values to a ...
    - Conditional DataGrid Item and using checkbox...
    - Fill .NET Listbox with SQL DataReader
    - Filling Dropdown box using Code-Behinds in C#
    - FLAMES code sample written in .NET What is F...





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway