Forstår ikke mine tællere
Jeg tester pt. 2 forskellige asp tællere på mit site http://www.Gisforum.dkMen de tæller ikke ens, hvorfor ved jeg ikke.
Jeg poster lige koderne:
Denne tæller mindre end nr. 2
<%
' Every time we count a user we will put the
' latest count value in the session variable "TotalCount"
' If Session Variable TotalCount is empty
' that mean this user is new and session variable
' But if Session Variable already has the value
' Then we will not count this user again.
If IsEmpty(Session("TotalCount")) Then
Call CountThisUser
End If
' It is good practice to use Functions and Sub procedure
' Because all the variables being used in sub or function
' are automatically destroyed when Sub or Function finish
' processing the code.
' So you can use these Variables again in other functions
Sub CountThisUser()
Dim objFSO ' FileSystemObject
Dim objTS ' TextStreamObject
Dim strFileName ' Counter text File Name
Dim intOldCount
Dim intNewCount
' Specify the Text file to store count value
' Because We Set Create = True
' File will be Created if it does not exist
strFileName = Server.MapPath("../db/Counter.txt")
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists(strFileName) Then
Set objTS = objFSO.OpenTextFile(strFileName, 1)
Else
Set objTS = objFSO.CreateTextFile(strFileName, True)
End If
If Not objTS.AtEndOfStream Then
intoldCount = objTS.ReadAll
Else
intoldCount = 0
End If
objTS.Close
intNewCount = intOldCount + 1
' Store the value of intNewCount in Session Variable
' So you can use it on different pages
Session("TotalCount")= intNewCount
' Write intNewCount value back to text file
Set objTS = objFSO.CreateTextFile(strFileName, True)
objTS.Write intNewCount
objTS.Close
Set objFSO = Nothing
Set objTS = Nothing
End Sub
%>
Kode nr. 2
</head>
<body style="font-family: Arial; font-size: 8 pt; font-weight: bold">
<font color="#000000">
<%
dim text_before_count, text_after_count, cookie_life_span
text_before_count = "Der har været" '| default: Du har haft
text_after_count = "besøgende." '| default: besøgende.
cookie_life_span = 1 '| default: 365
dim txt_file
set txt_file = Server.CreateObject("Scripting.FileSystemObject")
If NOT txt_file.FileExists(server.mappath("../DB/hit_counter.txt")) Then
dim create_txt_file
set create_txt_file = txt_file.CreateTextFile(server.mappath("../DB/hit_counter.txt"))
create_txt_file.write("0")
set create_txt_file = nothing
end if
dim get_hits_from_txt_file, hits_from_txt_file
set get_hits_from_txt_file = txt_file.OpenTextFile(server.mappath("../DB/hit_counter.txt"),1,false)
hits_from_txt_file = get_hits_from_txt_file.ReadLine
set get_hits_from_txt_file = nothing
dim request_cookie
request_cookie = request.cookies("hit_has_been_counted")
If NOT request_cookie = "hit_has_been_counted" then
hits_from_txt_file = hits_from_txt_file + 1
dim add_hit_to_text_file
set add_hit_to_text_file = txt_file.OpenTextFile(server.mappath("../DB/hit_counter.txt"),2,true)
add_hit_to_text_file.WriteLine(hits_from_txt_file)
set add_hit_to_text_file = nothing
response.cookies("hit_has_been_counted") = "hit_has_been_counted"
response.cookies("hit_has_been_counted").expires = date + cookie_life_span
end if
response.write "<span class=""hit_counter"">" & vbnewline &_
text_before_count &" " &_
hits_from_txt_file &_
" "& text_after_count & vbnewline &_
"</span>" & vbnewline
%>
Hviken er rigtig, når jeg vil have de aktuelle hits på min side ?
