ASP网站计数器防刷新代码

来源:百度知道 编辑:UC知道 时间:2024/06/03 06:37:13
在网上搜索了一个ASP计数器代码,使用发现没有防刷新功能,现请高手添加一个防刷新代码在里面,要求:刷新不+1,离开页面后重新登录+1.
1、在网站目录下新建一个文本:txtcounter.txt 在文本填写1或其他识字

2、新建一asp文件:count.asp,加入以下代码:

<%
CountFile=Server.MapPath("txtcounter.txt")
Set FileObject=Server.CreateObject("Scripting.FileSystemObject")
Set Out=FileObject.OpenTextFile(CountFile,1,FALSE,FALSE)
counter=Out.ReadLine
Out.Close
SET FileObject=Server.CreateObject("Scripting.FileSystemObject")
Set Out=FileObject.CreateTextFile(CountFile,TRUE,FALSE)
Application.lock
counter= counter + 1
Out.WriteLine(counter)
Application.unlock
Response.Write"document.write("&counter&")"
'为了在页面正确显示计数器的值,调用VBScript函数Document.write
Out.Close
%>

3、在需要计数的网页加入:总访问<script language="JavaScript" src="count.asp">次
jiuokle
具体怎么加入防刷新代码呀,,帮我写好,就是把防刷新代码插入上面代码中!!!急

if session("iscount")="" then
session("iscount")="iscount"
执行统计代码
end if

用session就可以解决了

在counter + 1 分面用一个session
if session("a") = 1 then
counter = counter
else
counter= counter + 1
end if

session("a") = 1

可以使用COOkie防止刷新,或者使用数据库把访问者IP记录下来,设置程序在多少时间内的刷新不统计