4:59 am Saturday, February 04, 2012
     
SERVER TRANSFER COMPLETE. UNDER CONSTRUCTION.
            Search About Contact Home
Session Hit Counter Tutorial
AaronOutpost : ASP / Tutorials / Counters / Session Hit Counter

Session Hit Counter Tutorial

Counters Tutorial

  1. Create a Text Hit Counter

  2. Create a Graphic Hit Counter

  3. Create a Text or Graphic Session Hit Counter

  4. Create an Active User Hit Counter using global.asa

Welcome to Part 3 of 4 Counter Tutorials. In Step1: Create a Text Hit Counter we learned to make a basic hit counter and in Step 2: Create a Graphic Hit Counter we learned how to display the hit count using loop and graphics. However the hit count increments every time the page is refreshed. In this tutorial we are going to discuss how to only count the user once using session cookies.

Now before we increment the hit counter we need to check that it has not already been incremented by the site visitor.

To do this we check to see if a session variable has been set on the visitors system. If the variable greater then or less then true then it has not been set so add a visitor to the count.

So "Old NumberVisitors + 1 = New NumberVisitors

If you are desperate and a loser you can change the number 1 to anything you want. If you get caught, would be quite hilarious.

'If the session variable is not true or non existent then Count user
If Session("blnCounterSet") <> True Then

'Add 1 to Number of Visitors

NumberVisitors = NumberVisitors + 1



    'Set the session variable to true
    Session("blnCounterSet") = True


End if

 

 

 

Finally this finished project should look something like this! Make sure it is saved in .asp format as mentioned before and must be run on an ASP2 enabled server.

Want to know how many users are on your page?
Create an Active User Hit Counter using global.asa

<html>

<head>

<title>Hit Counter</title>

</head>

<body bgcolor="white" text="black">

<div align="center">

<h3>Hit Counter</h3>

 

<%

 

Dim FileSystemObject, TextStreamObject, FileObject, NumberVisitors, LoopCount

 

'-----------------------------------------------------------
' Get and open hit count file

'-----------------------------------------------------------

Set FileSystemObject= Server.CreateObject("Scripting.FileSystemObject")

Set FileObject = FileSystemObject.GetFile(Server.MapPath("hit_counter.txt"))

Set TextStreamObject = FileObject.OpenAsTextStream

 

'-----------------------------------------------------------

' Increment count

'-----------------------------------------------------------

NumberVisitors = CLng(TextStreamObject.ReadAll)

 

'If the session variable is not true or non existent then Count user
If Session("blnCounterSet") <> True Then

'Add 1 to Number of Visitors

NumberVisitors = NumberVisitors + 1



    'Set the session variable to true
    Session("blnCounterSet") = True


End if

 

 

Set TextStreamObject = FileSystemObject.CreateTextFile(Server.MapPath("hit_counter.txt"))


TextStreamObject
.Write CStr(NumberVisitors)

 

 

Set FileSystemObject= Nothing

Set TextStreamObject = Nothing

Set FileObject = Nothing

 

'-----------------------------------------------------------
'Display the hit count as text

'-----------------------------------------------------------

%>

Text Version of Count <br>
<%=
NumberVisitors %>

<br>

<br>


'----------------------------------------------------------
'Display the hit count as images using loop

'-----------------------------------------------------------

For LoopCount = 1 to Len(NumberVisitors) %>

 

 

<img src="counter_images/<%= Mid(NumberVisitors, LoopCount, 1) %>.gif" alt="<%= Mid(NumberVisitors, LoopCount, 1) %>">

 

<% Next %>

 

<br>

</div>

</body>

</html>


AaronOutpost : ASP / Tutorials / Counters / Session Hit Counter


Random_Image
News & Updates

ASP Inline Calendar 3.9 (January 5, 2008)
Future Home of News & Updates (January 5, 2008)

 

Photo Special

Schedule an appointment

Available in & around:
Centreville VA, Spotsylvania VA,
Summersville WV, & Charleston WV
.

  • NAME YOUR PRICE
    • Email your:
    • Event
    • Hours Needed
    • Photos Needed
    • Disks or Prints
    • and Price You're Willing To Pay
ASP Inline Calendar

$100 Installation Special

PROFESSIONAL INSTALLATION OF YOUR ASP INLINE CALENDAR. REDUCE THE HASSLE, LET US INSTALL YOUR ASP INLINE CALENDAR. SEND A FORMAL REQUEST FOR INSTALLATION WITH SERVER ACCESS INFORMATION. WE WILL NEED FTP ACCESS ALONG WITH CONTROL PANEL ACCESS.

Purchase A Calendar
Information
Demo
Ask A Question

User must provide ftp access to server. Installations are not guaranteed. We work with your service provider to get your calendar installed.

 

Centreville, VA      -      Spotsylvania, VA      -      Charleston, WV      -      Summersville, WV

© Copyright AaronOutpost.com 2012. All rights reserved.