<%@ Language=VBScript %> <% Dim cnn ' ADO connection Dim rst ' ADO recordset Dim strDBPath ' path to our Access database (*.mdb) file Dim page Dim debug Dim table Dim today Dim sql Dim week page = Request.QueryString("page") debug = Request.QueryString("debug") today = Date ' Open a connection to the hitcounterdb strDBPath = Server.MapPath("hitcounterdb.mdb") Set cnn = Server.CreateObject("ADODB.Connection") table = "hitcounter" cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBPath & ";" ' Get page record sql = "SELECT * FROM " & table & " WHERE page = '"& page & "'" Set rst = cnn.Execute(sql) if not rst.EOF then diff = DateDiff("d", rst.Fields("lastupdate").Value, today) lastupdate = rst.Fields("lastupdate").Value if (Weekday(lastupdate) + diff) > 7 then week = 0 else week = rst.Fields("weekhits").Value end if if (diff > 0) then if Year(today) > Year(lastupdate) then sql = "UPDATE hitcounter SET todayhits='1', weekhits='" & week + 1 & "', monthhits='1', yearhits='1', yearagohits='" & rst.Fields("yearhits").Value & "' WHERE page = '"& page & "'" else if Month(today) > Month(lastupdate) then sql = "UPDATE hitcounter SET todayhits='1', weekhits='" & week + 1 & "', monthhits='1', yearhits='" & rst.Fields("yearhits").Value + 1 & "', lastupdate='" & today &"' WHERE page = '"& page & "'" else sql = "UPDATE hitcounter SET todayhits='1', weekhits='" & week + 1 & "', monthhits='" & rst.Fields("monthhits").Value + 1 & "', yearhits='" & rst.Fields("yearhits").Value + 1 & "', lastupdate='" & today &"' WHERE page = '"& page & "'" end if end if else sql = "UPDATE hitcounter SET todayhits='" & rst.Fields("todayhits").Value + 1 & "', weekhits='" & week + 1 & "', monthhits='" & rst.Fields("monthhits").Value + 1 & "', yearhits='" & rst.Fields("yearhits").Value + 1 & "', lastupdate='" & today &"' WHERE page = '"& page & "'" end if else sql = "INSERT INTO hitcounter (page, todayhits, weekhits, monthhits, yearhits, lastupdate) VALUES( '" & page & "',1,1,1,1,'" & today &"')" end if Err.Clear Set rst = cnn.Execute(sql) if debug = "yes" then Response.Write Err.Source & " " & Err.number & " " & Err.Description end if %>