Note: all scripts examples included in these Web pages are absolutely free. You can copy, use, and modify these scripts anyway you want. The scripts are published without warranty of any kind.
This script keeps the counter value in the access database. Of course, you
can use any other ODBC data source you want. You can use
The ASP script reads the
images of digits from the digit bars (GIF images containing all digits
from 0 to 9).
<IMG SRC="counter.asp?id=MYTEST&seq=default&cells=7">
| Field | Type | Indexed | Means |
|---|---|---|---|
| ident | AutoNumber | Yes | For your needs |
| id | Text | Yes | Id parameter from the HTTP query string identifies the corresponding Web page |
| count | Number | No | The number of hits to the corresponding Web page |
| File counter.asp |
<%
Response.ContentType="image/gif"
Response.Expires=0
'The directory where GIF bars are placed. Ends with \
workdir="c:\gifbars\"
'Set this to False if you want to disable auto inserting
'new counter records to database on every hit with unique
'id string
auto_insert=True
id=Trim(Request.QueryString("id"))
seq=Trim(Request.QueryString("seq"))
if seq="" then seq="default"
cells=Trim(Request.QueryString("cells"))
if cells="" then cells=5 else cells=cells*1
set conn=Server.CreateObject("ADODB.Connection")
conn.Open "Webcounter"
sql="select count,ident from main where id='" & id & "'"
set rs=conn.Execute(sql)
if not rs.EOF then
count=rs("count")+1
ident=rs("ident")
rs.close()
conn.Execute("update main set count=count+1 where ident=" & ident)
conn.close()
ShowNumbers()
else
rs.close()
if auto_insert=True and id<>"" then
conn.Execute("insert into main (id,count) values ('" & id & "',1)")
count=1
ShowNumbers()
end if
conn.close()
end if
Sub ShowNumbers()
set g=CreateObject("shotgraph.image")
filename=workdir & seq & ".gif"
if g.GetFileDimensions(filename,xsize,ysize,pal)<>1 then Exit Sub
xdigit=xsize\10
g.CreateImage xdigit*cells,ysize,UBound(pal)+1
g.InitClipboard xsize,ysize
g.SelectClipboard True
for i=0 to UBound(pal)
g.SetColor i,pal(i,0),pal(i,1),pal(i,2)
next
g.ReadImage filename,pal,0,0
for i=1 to cells
k=GetDigit(count,cells-i)
g.Copy (i-1)*xdigit,0,xdigit,ysize,k*xdigit,0,"SRCCOPY"
next
Response.BinaryWrite g.GifImage(-1,1,"")
End Sub
Function GetDigit(number,position)
number1=number\(10^position)
tmp=number1\10
GetDigit=number1-tmp*10
End Function
%>
|