Instructions for use
1. Add a reference to the AntiRefresh. asp file at the top of the page to be protected, for example:
<! -- # Include virtual = "AntiRefresh. asp" -->
2. Add the call code.
Copy codeThe Code is as follows: <%
Const VarNameDateArr = "www_domai_net_App_DataArr" 'queue name
Const VarNameIPArr = "www_domai_net_App_IPArr" 'queue name
Dim objAntiRefresh
Set objAntiRefresh = new AntiRefresh
ObjAntiRefresh. BufferSize = 100 'queue size
ObjAntiRefresh. CacheItemAvailTime = 2' Interval
If Not objAntiRefresh. IsValidAccess () Then
Set objAntiRefresh = Nothing
Response. Write ("your access has been frequent in the past. Please try again in 2 seconds .")
Response. End ()
End If
Set objAntiRefresh = Nothing
%>
Note that
Const VarNameDateArr = "www_domai_net_App_DataArr" 'queue name
Const VarNameIPArr = "www_domai_net_App_IPArr" 'queue name
For example. asp and search. add an anti-Refresh tool in asp. Copy the above call code to these two pages, or ensure that the code of the two pages is consistent. In this way, if you access the List. asp page, you will not be able to access the List. asp or Search. asp page within 2 seconds.
If you want two independent pages, you can access the List. after asp, you will not be able to access the List again within 2 seconds. asp, but you can access Search. asp. Otherwise, you must ensure that the Const VarNameDateArr = "xxx" and Const VarNameIPArr = "xxx" are different for the two pages. For example, you can use xxxList for the first page, the first page uses xxxSearch,
For example:
Const VarNameDateArr = "www_domai_net_App_DataArr_Search" '(_ List)
Const VarNameIPArr = "www_domai_net_App_IPArr_Search" '(_ List)
Nagging these are for friends who are not very familiar with the code so that they can use the code. If you know Asp, the above will be a good understanding for you.
The following is the source code of the AntiRefresh. asp file.Copy codeThe Code is as follows: <%
'***************************************
'* Page anti-Refresh module *
'* WDFrog, 2007-8-16
'***************************************
Class AntiRefresh
Private IPArr, DateArr
Private m_BufferSize
Private m_CacheItemAvailTime
Private Sub Class_Initialize ()
Application. Lock ()
M_BufferSize = 100
M_CacheItemAvailTime = 2
End Sub
Private Sub Class_Terminate ()
Application. UnLock ()
End Sub
Public Property Get CacheItemAvailTime
CacheItemAvailTime = m_CacheItemAvailTime
End Property
Public Property Let CacheItemAvailTime (Value)
M_CacheItemAvailTime = Value
End Property
Public Property Get BufferSize
BufferSize = m_BufferSize
End Property
Public Property Let BufferSize (Value)
M_BufferSize = Value
End Property
Private Sub EnsureArr ()
If IsArray (Application (VarNameDateArr) Then
DateArr = Application (VarNameDateArr)
Else
ReDim DateArr (BufferSize)
End If
If IsArray (Application (VarNameIPArr) Then
IPArr = Application (VarNameIPArr)
Else
ReDim IPArr (BufferSize)
End If
End Sub
Public Function IsValidAccess ()
Dim ip, I
Ip = GetIP ()
IsValidAccess = True
EnsureArr ()
For I = 1 To BufferSize
If IPArr (I) = ip Then
If DateDiff ("s", CDate (DateArr (I), Now () <CacheItemAvailTime Then
IsValidAccess = False
Exit Function
End If
End If
Next
Call QueueHandle ()
DateArr (1) = Now ()
IPArr (1) = ip
Application (VarNameIPArr) = IPArr
Application (VarNameDateArr) = DateArr
End Function
Public Function implements AchE ()
Set Application (VarNameDateArr) = Nothing
Set Application (VarNameIPArr) = Nothing
End Function
Private Sub QueueHandle ()
Dim I, j
For I = BufferSize-1 To 1 Step-1
DateArr (I + 1) = DateArr (I)
Next
For j = BufferSize-1 To 1 Step-1
IPArr (j + 1) = IPArr (j)
Next
End Sub
Private Function GetIP ()
Dim strIPAddr
If Request. ServerVariables ("HTTP_X_FORWARDED_FOR") = "" OR InStr (Request. ServerVariables ("HTTP_X_FORWARDED_FOR"), "unknown")> 0 Then
StrIPAddr = Request. ServerVariables ("REMOTE_ADDR ")
ElseIf InStr (Request. ServerVariables ("HTTP_X_FORWARDED_FOR"), ",")> 0 Then
StrIPAddr = Mid (Request. ServerVariables ("HTTP_X_FORWARDED_FOR"), 1, InStr (Request. ServerVariables ("HTTP_X_FORWARDED_FOR"), ",")-1)
ElseIf InStr (Request. ServerVariables ("HTTP_X_FORWARDED_FOR"), ";")> 0 Then
StrIPAddr = Mid (Request. ServerVariables ("HTTP_X_FORWARDED_FOR"), 1, InStr (Request. ServerVariables ("HTTP_X_FORWARDED_FOR"), ";")-1)
Else
StrIPAddr = Request. ServerVariables ("HTTP_X_FORWARDED_FOR ")
End If
GetIP = (Trim (Mid (strIPAddr, 1, 30 )))
End Function
End Class
%>
Asp prevents refreshCopy codeThe Code is as follows: Sub chkreflash ()
Dim ScriptName
ScriptName = lcase (request. ServerVariables ("PATH_INFO "))
Dim posttime, DoReflashPage, ReflashPage, SplitReflashPage
Posttime = 1' prevents refresh time
DoReflashPage = false
ReflashPage = "| Article_one.asp"
SplitReflashPage = split (ReflashPage, "| ")
For I = 0 to ubound (SplitReflashPage)
If instr (scriptname, SplitReflashPage (I)> 0 then
DoReflashPage = true
Exit
End if
Next
If (not isnull (session ("ReflashTime") and posttime> 0 and DoReflashPage then
If DateDiff ("s", session ("ReflashTime"), Now () <posttime then
Call msg ("warning! The system has recorded your IP address and the number of refresh times. \ N please do not refresh this page continuously in "& posttime &" seconds! ","-1 ")
Else
Session ("ReflashTime") = Now ()
End if
Elseif isnull (session ("ReflashTime") and posttime> 0 and DoReflashPage then
Session ("ReflashTime") = Now ()
End if
End Sub
Add chkreflash to the first part of the page.