Use a page counter with asp

K

Krechting

Hi All,

All I want is a small graphical page counter on my homepage.
I'm using an access db and want to track how many times the
pages were used (logged on to).
All the graphical counters on the internet point to a website
but my project runs on a localhost.

Regards
Marco
 
R

Ray at

If you search Google, you will find a number of page counter solutions for
ASP. You can use a component, store hits in a DB, use a file that increases
in size with each visit, or probably something else. Once you get the
number, you can build your image by having 10 gif images, 0.gif, 1.gif, etc.
And then you use the value of your count to determine which images to
display in your page.

Page counters are so 90s though! :p

Ray at work
 
C

Curt_C [MVP]

just store the count in db.
Increment by 1 each hit.
Then just parse the count, replacing each digit with the individual
graphic/image.
 
B

Brynn

This is an old counter I used to use ... I made it for kicks
It uses a table in a database. The table name is zcounter
The column names are zpage and zhits
This way you can also have different pages being counted if you want.

Another thing I did is have it create a cookie for the user that
expires in a day. This will let a users computer only add to the
counter once a day ... granted, only if they have cookies on.

I also, instead of images, used the CSS at the top to control design
as to avoid images, but you could easily change that in the code.

Have fun ... I will make an updated counter script and have it on my
website sometime in the next couple weeks, just for fun :)

Brynn
www.coolpier.com (new website under construction)






<style type="text/css">
td.coolpier_counter {background-color:#F4F4F4; color:#336699;
font-size:16; font-weight:bolder;}
</style>

<%
'//CHANGE CONNECTION STRING
connString="your connection string"

Sub coolpier_counter(thePage)
'//Need a table called zcounter
'//Two fields: zpage (text), zhits (number)
Set conn=Server.CreateObject("ADODB.Connection")
conn.Open(connString)
If Request.Cookies("zhit")<>"1" Then
zsql="UPDATE zcounter SET zhits=zhits+1 WHERE
zpage='" & thePage & "';"
conn.Execute(zsql)
Response.Cookies("zhit")="1"
Response.Cookies("zhit").expires=Date()+1
End If
zsql="SELECT zhits FROM zcounter WHERE zpage='" &
thePage & "';"
Set rs=conn.Execute(zsql)
theCount=rs(0)
rs.Close: Set rs=nothing
conn.Close: Set conn=nothing

With Response
.Write "<table align=center cellpadding=3
cellspacing=1 border=0><tr>"
.Write "<td class=""coolpier_counter"">Hits: </td>"
numLength=Len(theCount)
For n=1 to Len(theCount)
.Write "<td class=""coolpier_counter""
width=15>" & Mid(theCount, n, 1) & "</td>"
Next
.Write "</tr></table>"
End With
End Sub

coolpier_counter("yourpage.asp")
%>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top