% 'Sub procedure for incrementing the hit counters 'This is put in a Private Sub Prcedure so it does not interfere with other variables you may have in the script 'This will stop errors and variables over writing each other Private Sub IncrementHitCount(strAccessDBPath) 'Dimension Variables Dim adoCon 'Database Connection Variable Dim strCon 'Holds the Database driver and the path and name of the database Dim adoRec 'Database Recordset Variable Dim strAccessDB 'Holds the name a root to the Access Database Dim strSQL 'Database query sring Dim lngTotalHitCount 'Holds the total visitor number Dim lngResetHitCount 'Holds the visitor number since reset Dim strPageName 'Holds the name of the page and the path to the page 'Error handler 'On error resume next 'Initialise the path to the access database strAccessDB = strAccessDBPath & "hit_count.mdb" 'Read in the name and path to the page strPageName = Request.ServerVariables("SCRIPT_NAME") 'Create a connection odject Set adoCon = Server.CreateObject("ADODB.Connection") '------------- If you are having problems with the script then try using a diffrent driver or DSN by editing the lines below -------------- 'Database connection info and driver (if this driver does not work then comment it out and use one of the alternative drivers) 'strCon = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath(strAccessDB) 'Alternative drivers faster than the basic one above 'strCon = "Provider=Microsoft.Jet.OLEDB.3.51; Data Source=" & Server.MapPath(strAccessDB) 'This one is if you convert the database to Access 97 strCon = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath(strAccessDB) 'This one is for Access 2000 'If you wish to use DSN then comment out the driver above and uncomment the line below (DSN is slower than the above drivers) 'strCon = "DSN=hitCountDB" 'Place the DSN name after the DSN= '--------------------------------------------------------------------------------------------------------------------------------------------- 'Set an active connection to the Connection object adoCon.Open strCon 'Create a recordset object Set adoRec = Server.CreateObject("ADODB.Recordset") 'Initalise the strSQL variable with an SQL statement to query the database to get the hit counts for the page strSQL = "SELECT tblHitCount.* FROM tblHitCount " strSQL = strSQL & " WHERE tblHitCount.Page ='" & strPagename & "';" 'Set the cursor type property of the record set to Keyset so we can navigate through the record set adoRec.CursorType = 2 'Set the Lock Type for the records so that the record set is only locked when it is updated adoRec.LockType = 3 'Open the recordset adoRec.Open strSQL, strCon 'If there is no record relating to this page in the database then set the number of page hits to 1 and initilise a new record in the recordset If adoRec.EOF Then 'Initilise the new values for the database lngTotalHitCount = 1 lngResetHitCount = 1 'Initilise a new record for the recordset adoRec.AddNew 'Place the page name into the recordset adoRec.Fields("Page") = strPageName 'If there is a record relating to the page then read in the value from the recordset and increment Else 'Read in the values form the database lngTotalHitCount = CLng(adoRec("Total_Counter")) lngResetHitCount = CLng(adoRec("Reset_Counter")) 'Increment the hit counters lngTotalHitCount = lngTotalHitCount + 1 lngResetHitCount = lngResetHitCount + 1 End If 'Place the vlues into the recordset adoRec.Fields("Total_Counter") = lngTotalHitCount adoRec.Fields("Reset_Counter") = lngResetHitCount 'Place the updated recordset into the database adoRec.Update 'Requery the database adoRec.Requery 'Close Server Objects Set adoCon = Nothing Set adoRec = Nothing End Sub 'Dimenstion Variables Dim strDatabasePath 'Holds the path to the databse if you are using the hit count on a file not in the same folder as the database 'Initialise the path to the access database if inside another folder other than that the databse is within (don't add database name, just the path) strDatabasePath = ("/baze/") 'Call the sub procedure to increment the hit counters Call IncrementHitCount(strDatabasePath) %>
|
|
|
|
Dragi
gosti! |