webForumDet fria alternativet

Cookie Hjälp

0 svar · 167 visningar · startad av Lazerzubb

LazerzubbMedlem sedan mars 2000542 inlägg
#1

HÄr nedan är koden till en räknare.
Den tittar om en cookie finns för den besökta sidan.
Jag skulle vilja ha lägga till ett värde så den funkade som en vanlig räknare den gör en cookie på första sida du går in på inom domän och lägger till +1 i databasen men när du klickar vidare så läggs inget till i kolumen.
Men jag vill även ha den existerade räknaren i koden neran.
Svårt och förstå? Jag brukar förklara dåligt :)

<!--#include file="adovbs.inc"--> 
<% 
present_page = Request.ServerVariables("SCRIPT_NAME") 
' Gets the name of the current page 

if Request.Cokies("HitCount")(present_page) <> "Visited" then 
' Checks to see if the cookie already exists for this page 
' If if does then a count is not added and the rest of the code is discarded 
' If it doesn't then we add the hit 

  set conn=server.createobject("adodb.connection") 
  ConnString = "DRIVER=Microsoft Access Driver (*.mdb);" 
  ConnString = ConnString & "DBQ=" &Server.MapPath("counter.mdb") 
' The database is found in the root path in the databases folder 
  conn.Open ConnString 

  set rsRecord = Server.CreateObject("ADODB.RecordSet") 
  sqltext = "SELECT * FROM counter where page='" & present_page & "'" 
  rsRecord.Open sqltext,conn,3,3 

' This db connection checks whether the page already exists in the database
' If it does then we just update the record.
' If it doesn't exist then we add a new record. 

  If rsRecord.recordcount = 0 then 
' This uses an if statemtent if the page doesn't exist 

    set rs = Server.CreateObject("ADODB.RecordSet") 
    rs.cursorlocation = adUseServer 
    rs.CursorType = adOpenKeySet 
    rs.LockType = adLockOptimistic 

    rs.open "counter",conn, , ,adCmdTable 
    rs.addnew 

    rs("page") = present_page 

    rs("hitcount") = 1 

    rs("lasthit") = now() 

    RS.update 

    Response.Cokies("HitCount")(present_page) = "Visited" 
' The page has been visited and will not be counted again 

  else 
' The page exists in the database 

    dim rs, formercount 
    set rs = Server.CreateObject("ADODB.RecordSet") 
    rs.cursorlocation = adUseServer 
    rs.CursorType = adOpenForwardOnly 
    rs.LockType = adLockOptimistic 

    sqlstate = "SELECT * FROM counter where page='" & present_page & "'" 
    rs.open sqlstate,conn, , ,adCmdText 

    hitcount = rs("hitcount") 
    rs("hitcount") = hitcount + 1 

    rs("lasthit") = now() 

    rs.update 

    Response.Cokies("HitCount")(present_page) = "Visited" 
' The page has been visited and will not be counted again 

  end if 
end if 
%>

------------------
Helvetet är den plats där engelsmännen lagar maten, Italienarna dirigerar trfiken och tyskarna står för underhållningen.

132 ms totalt · 3 externa anrop · v20260731065814-full.fb544a5a
0 ms — hämta forumlista (cache)
0 ms — hämta statistik (cache)
128 ms — hämta tråd, inlägg och bilagor (db)