Implementation of a number of methods, this article mainly introduces the use of database to achieve a simple counter!
' Save As Count.asp ' below
<%
Set conn=server.createobject ("ADODB. Connection ")
Conn. Open "Driver={microsoft Access driver (*.mdb)};d bq=" & Server.MapPath ("Count.mdb")
%>
<%on Error Resume next%>
<%sql= "Update count set Hit=hit+1%><%conn. Execute (SQL)%>
<%sql = "SELECT * from Count
Set Rs=conn.execute (SQL)
%>
<%
' Update weekly daily data
Lasthit=rs ("Lasthit")
Tdate=year (now ()) & "-" & Month (now ()) & "-" & Day (now)
If Trim (lasthit) =trim (tdate) Then
Sql= "Update site set dayhit=dayhit+1 where id=" &request ("id")
Conn. Execute (SQL)
' Response.Write ' success '
Else
Sql= "Update site set dayhit=1 where id=" &request ("id")
Conn. Execute (SQL)
' Response.Write ' ERROR '
End If
Sql= "Update site set lasthit= '" &tdate& "where id=" &request ("ID")
Conn. Execute (SQL)
P_year=cint (Today ())-cint (year (lasthit))
P_month=cint (Month (now))-cint (month (lasthit))
P_day=cint (Today ())-cint (Day (Lasthit))
Period_time= ((p_year*12+p_month) *30+p_day)
If CInt (period_time) =<cint (7) Then
Sql= "Update site set weekhit=weekhit+1 where id=" &request ("id")
Conn. Execute (SQL)
Else
Sql= "Update site set weekhit=1 where id=" &request ("id")
Conn. Execute (SQL)
End If
%>
document.write (' <tr> <td width= "100%") Dayhit times today to visit <%=rs ("%>"), visit <%=rs ("Weekhit")%> times this week, Total Access <%=rs ("hit")%> times </td> tr> ');
<%rs.close
Set rs=nothing%>
Build a database: Build a count of the MDB library, and then build a table count, in the table field
Hit Digital type
Dayhit Digital Type
Weekhit Digital Type
Lasthit Date Type