gotFusion.com....... Where your adventure begins
Full Service Web HostingNetObjects Fusion 7 Websites Portal

 


 

A Simple Counter using ASP and Access

Text based


Image Based



This example we will be using an Access Database
with a DSN-Less Connect Method. The Database can be obtained Here.

The asp file should reside in the root of your web site along with the access database.
Comments are noted in ASP using a ' single quote
You can invoke this on your splash page minus the response statements and include a simple redirect script when the asp is finished to go where ever you want, or, use it in conjunction with an Iframe to display results as a counter. This example will use an Iframe to display counter values

<%
'First we declare our variables to use

dim vbrowser, vip, vhost, today, connStr, rs, vs, bs, visitx, returnx, bscount

'Next we assign values to the variables

vbrowser=Request.ServerVariables("HTTP_USER_AGENT")
vip=Request.ServerVariables("REMOTE_ADDR")
vhost=Request.ServerVariables("HTTP_REFERER")
today=cdate(date())
connStr = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("tracker.mdb")

' We now set the format for our work as an Recordset Object

Set rs = Server.CreateObject("ADODB.RecordSet")
Set vs = Server.CreateObject("ADODB.RecordSet")
Set bs = Server.CreateObject("ADODB.RecordSet")

' We are now ready to open the connection to the access database
'This opens the returning table to add return visitor information

vs.Open "returning", connStr, 2, 2

' This opens the database and searches for the ipaddress from the visitor for the current date
' If it is not found it will create a record of the visit and append the information to the visits table
' The visits table has additional fields not listed here for auto inserting date and time when the record is
' added.

rs.Open "select * from visit WHERE [visit.ipad] ='" & vip & "'AND cdate([visit.date]) ='" & date() &"' ORDER BY [visit.date] ASC", connStr, 3, 4

If rs.RecordCount =0 Then
visitx=1
returnx=0
rs.close
rs.Open "visit", connStr, 2, 2
rs.AddNew
rs("browser") = vbrowser
rs("ipad") = vip
rs("domain") = vhost
rs.Update
Else

' If the IP address and the date match then we open the returning table and append a record as a return
'  visit for the day. We do this so that accurate counts for unique visits are recorded and a total count of return
'  visits is available

' This appends the returning table if it is a return visit

visitx = 0
vs.AddNew
vs("browser") = vbrowser
vs("ipad") = vip
vs("domain") = vhost
vs.Update
vs.close
vs.Open "select * from returning WHERE [returning.ipad] ='" & vip & "' ORDER BY [returning.date] ASC", connStr, 3, 4
returnx = vs.RecordCount

End If

' Now lets display the results in text
' This opens the visit table to gather the total number of visitors

bs.Open "select * from visit", connStr, 3, 4
bscount= bs.RecordCount
response.write "Unique Visitors to date: <b>" & bscount & "</b><br>"
If visitx = 1 then
response.write "Welcome. This is your 1st visit today."
else
end if
If returnx > 0 then
response.write "Welcome Back.<br>"
response.write "This is your <b>" & returnx & "</b> visit to this site."
else
end if

'OR
' we can display the results as images. This will require you to create gifs representing numbers 0 - 9
'and naming them 0.gif, 1.gif and so on
' Here is the syntax
' Here we are looking at the recordcount as a string and counting the number of characters
' Once we have that we create a loop that will create numerous response statements for each numerical
' character encountered and then display the appropriate gifs in order.
' If you plan on using this simply remark out the response statements above. Or if you choose not to use
' graphics rem the following line out


dim lennum, strnum
strnum=trim(cstr(bs.recordCount))
lennum= len(bs.recordCount)
response.write"<img src='lend.gif'>"
for i = 1 to lennum
response.write "<img src='" & mid(strnum,(i),1) & ".gif'>"
next
response.write"<img src='rend1.gif'>"

' Now we can close the databases and release the page

bs.close
vs.Close
rs.close
Set rs = Nothing
Set rs = Nothing
Set bs= Nothing
' for redirection use the following additional script and remove or comment out the response statements
' response.redirect( "http://www.yoursite.com" )

%>
 

To utilize this in NetObjects, an Iframe is an excellent choice.
Steps for Use:

  • Create a blank page
  • Use no masterborders or frames
  • Name the page counter
  • Insert asp as the page extension
  • Use 1st Line or InsertIt to place the following at the first line position
  • <%@ language="VBscript"%>

    Next copy the code from this page and paste into Notepad
    [This will remove any formatting].
  • Select all text and copy back to the clipboard.
  • Create a Text Object on the blank layout
  • double click the text object to bring up the cursor
  • Press Ctrl+T
  • Paste the code.
  • Click Okay
  • Publish the page to the root of your site
    [ or any folder if publishing site structure for the page you want to monitor ]
  • Either add the visit-tracker.mdb as an asset and publish or, using a third party app like Cuteftp Pro to transfer the visit-tracker.mdb
    ** [ make sure it is published or transferred to the correct location ]
  • Select the page you wish the counter to show
  • Create either a 1 x 1 table or a text Object and place it where you wish.
  • Double click to bring up the cursor
  • Press Ctrl+T and insert the following making sure the source path is correct for your site

    <Iframe src="counter.asp" frameborder=0 width="304" height="75" scrolling="no">
    </iframe>

    Click Okay
  • Publish the page and enjoy

View the PREVIOUS page in this tutorial

Return to the TOP of this page

View the NEXT page in this tutorial


|  Fusion  |  Web Design  |  Hosting  |  Resources  |  gotFusion Store  | 

Problems with this page?  

All content copyright © 2002 gotFusion LLC.  The name gotFusion and the gotFusion ® logo are registered trademarks of gotFusion LLC
Copyright, legal notice & privacy statement