VB icon

Unique w/ database & more than one page

Email
Submitted on: 1/5/2015 2:28:00 PM
By: atwinda (from psc cd)  
Level: Intermediate
User Rating: By 3 Users
Compatibility: ASP (Active Server Pages)
Views: 590
 
     This is an update to my Unique Hit Counter that used a text file to keep track of all hits. With a database, more than one page on your site can be monitored by this file. It uses the servervariable url to determine what page it needs to add a hit to. As with my last hit counter, it uses cookies to keep track of who has been and who hasn't. I built my Text to Images into this script. As with that submission, you have to make your own images. They don't have to be any special height, or width. My images start with "cnt_" and have a numerical value coresponding with the value passed (that means you need images cnt_0 - cnt_9). I also have a cnt_start and cnt_end image to make everything look nice. Save this save as something like counter.asp and just use an include (). You can use it on every page on your site to track where people go, and what-not.
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
'**************************************
' Name: Unique w/ database & more than one page
' Description:This is an update to my Unique Hit Counter that 
used a text file to keep track of all hits. With
a database, more than one page on your site can be
monitored by this file. It uses the servervariable
url to determine what page it needs to add a hit 
to. 
As with my last hit counter, it uses cookies to
keep track of who has been and who hasn't. I built
my Text to Images into this script. As with that 
submission, you have to make your own images. They
don't have to be any special height, or width. My
images start with "cnt_" and have a numerical 
value coresponding with the value passed (that 
means you need images cnt_0 - cnt_9). I also have
a cnt_start and cnt_end image to make everything
look nice. 
Save this save as something like counter.asp and
just use an include (<!-- #include file="counter.asp" //-->). You can use it on every
page on your site to track where people go, and
what-not.
' By: atwinda (from psc cd)
'**************************************

<%
Dim objHitConn, strHitSQL, objHitRs, intHits, strHitFile
Set objHitConn = Server.CreateObject("ADODB.Connection")
objHitConn.Provider = "Microsoft.Jet.OLEDB.4.0"
objHitConn.Open Server.MapPath("counter.mdb")
'counter.mdb needs to have a table named "Main"
'along with two colunms: "Page" and "Hits"
strHitFile = Request.ServerVariables("url")
strHitSQL = "SELECT Page, Hits From Main Where Page='" & strHitFile & "'"
Set objHitRs = Server.CreateObject("ADODB.Recordset")
objHitRs.Open strHitSQL, objHitConn, 1, 2
If objHitRs.EOF Then
	objHitRs.AddNew
	intHits = 0
	objHitRs.Fields("Page").Value = strHitFile
Else
	intHits = objHitRs.Fields("Hits").Value
End If
intHits = CInt(intHits) + 1
objHitRs.Fields("Hits").Value = CStr(intHits)
objHitRs.Update
objHitRs.Close
objHitConn.Close
set objHitRs = nothing
set objHitConn = nothing
Call DisplayImg(intHits)
Function DisplayImg(intNum)
Dim itmCur, tmpCur
Response.Write "<img src='images/cnt_start.gif'>"
For itmCur = 1 To Len(intNum)
	tmpCur = Mid(cStr(intNum), itmCur, 1)
	Response.Write "<img src='images/cnt_" & tmpCur & ".gif'>"
Next
Response.Write "<img src='images/cnt_end.gif'>"
End Function
%>


Other 2 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Intermediate category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.