以下是引用片段:
<STYLE type=text/css>
body { font-family: "Tahoma"; font-size: 12px; text-decoration: none}
</STYLE>
<%
dim User_login,Count_Result,Count_Content,CompareDate
Count_Result="2.asp" ‘这里设定记录计数器数据的文件名为2.asp
CompareDate=10 ‘设定比较时间,无单位
User_login=Request.Cookies("User_login") ‘取得用户Cookies
If User_login="" Then ‘如果cookies不存在,就赋予用户一个Cookies,并将计数器加一
response.write "用户没有cookies,线在创建<p>"
Call CreateCookies
Call ModifyCount
Else
response.write "用户cookies存在,现在去比较时间是否过期<p>"
Call IndentifyDate
End If
‘Response.Redirect Count_Result
‘修改计数器文件
Sub ModifyCount
If CheckFileExists(Count_Result)=1 Then ‘计数器文件存在
response.write "计数器文件存在,现在去增加计数器的数值<p>"
Call AddCount
ElseIf CheckFileExists(Count_Result)=0 Then ‘计数器文件不存在就添加这个文件
response.write "计数器文件不存在,现在区创建这个文件,并将记录设定为1<p>"
Call CreateCount
End If
End Sub
‘给计数器文件增加数值
Sub AddCount
response.write "给计数器加一完毕<p>"
Count_Content=CInt(ReadTextFile(Count_Result))+1 ‘读这个文件的内容and给count_result.asp加一
Call SaveTextFile(Count_Result, Count_Content)
End Sub
‘创建计数器文件
Sub CreateCount
response.write "创建文件完毕<p>"
CreateFile(Count_Result) ‘创建文件
Count_Content=1 ‘计数器归零
Call SaveTextFile(Count_Result, Count_Content)
End Sub
‘判断cookies相差时间时间
Sub IndentifyDate
If DateDiff("s",cDate(User_login), Now())>CompareDate Then ‘用户机上的cookies所记录的时间与当前相差是否超过10s’
response.write "超过10秒,cookies已经过期,现在给计数器加一<p>"
Call ModifyCount
else
response.write "短于10秒钟,没有过期,计数器不增长<p>"
End If
response.write "现在给cookies重新赋予现在的时间"
Call CreateCookies
End Sub
‘给用户创建一个新的cookies并赋值,设定cookies失效时间为1天
Sub CreateCookies
Response.Cookies("User_login")=Now()
Response.Cookies("User_login").Expires=date+1
End Sub
‘ 检查文件是否存在
Function CheckFileExists(strFile)
Dim strTestFile, objFSO
strTestFile = Server.Mappath(strFile)
Set objFSO = CreateObject("Scripting.FileSystemObject")
‘ 检查文件是否存在
If objFSO.FileExists(strTestFile) Then
CheckFileExists = 1
Else
CheckFileExists = 0
End If
Set objFSO = Nothing
End Function
‘写文件
Sub SaveTextFile(strFile, strFileInnew)
Dim objFSO, objOutStream, strTestFile
strTestFile = Server.Mappath(strFile)
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
Set objOutStream = objFSO.OpenTextFile(strTestFile,2,True,False)
objOutStream.WriteLine(strFileInnew)
objOutStream.Close
Set objOutStream = Nothing
Set objFSO = Nothing
End Sub
‘ 读文件的内容
Function ReadTextFile(strFile)
Dim strTestFile, objFSO, objInStream
strTestFile = Server.Mappath(strFile)
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
Set objInStream = objFSO.OpenTextFile (strTestFile,1, False, False)
ReadTextFile = objInstream.ReadALL
objInStream.Close
Set objInStream = Nothing
Set objFSO = Nothing
End Function
Function CreateFile(strFile)
Dim strTestFile, objFSO, objStream
strTestFile = Server.Mappath(strFile)
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists(strTestFile) Then
CreateFile = 0
Else
‘ 新建文本文件
Set objStream = objFSO.CreateTextFile(strTestFile, True)
objStream.write(filecontent)
CreateFile = 1
Set objFile = Nothing
End If
Set objFSO = Nothing
End Function
%>
|
评论前必须登录!
注册