使用說明
1.在要保護的頁面頂部加如對AntiRefresh.asp檔案的引用如:
<!--#include virtual="AntiRefresh.asp" -->
2.接著添加調用代碼
複製代碼 代碼如下:<%
Const VarNameDateArr="www_domai_net_App_DataArr" '隊列名稱
Const VarNameIPArr="www_domai_net_App_IPArr" '隊列名稱
Dim objAntiRefresh
Set objAntiRefresh= new AntiRefresh
objAntiRefresh.BufferSize=100 '隊列大小
objAntiRefresh.CacheItemAvailTime=2 '間隔時間
If Not objAntiRefresh.IsValidAccess() Then
Set objAntiRefresh=Nothing
Response.Write("您的訪問過去頻繁請2秒後再試.")
Response.End()
End If
Set objAntiRefresh=Nothing
%>
其中要注意的是
Const VarNameDateArr="www_domai_net_App_DataArr" '隊列名稱
Const VarNameIPArr="www_domai_net_App_IPArr" '隊列名稱
比方你要在List.asp與search.asp中加入通一個防重新整理器,那麼你把上面的調用代碼分別複製到這兩個頁面,或者保證兩個頁面的掉用代碼一致。這樣的效果是,你訪問了List.asp頁那麼你在2秒內將不能訪問List.asp或Search.asp頁
如果你要2個頁面獨立,即你訪問List.asp後,你會在2秒內不能再次訪問List.asp,但是你可以訪問Search.asp,反之毅然,那麼你就要保證2個頁面的 Const VarNameDateArr="xxx",Const VarNameIPArr="xxx"不同,比方第一個也面你用xxxList,第個個頁面用xxxSearch,
如:
Const VarNameDateArr="www_domai_net_App_DataArr_Search" '(_List)
Const VarNameIPArr="www_domai_net_App_IPArr_Search" '(_List)
嘮叨這些是給那麼不太懂的朋友,以便他們能使用這些代碼,如果你懂Asp那麼以上的對你來說就很好理解了。
下面是AntiRefresh.asp檔案源碼 複製代碼 代碼如下:<%
'***************************************
'* 頁面防重新整理模組 *
'* 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 ClearCache()
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防止重新整理複製代碼 代碼如下:Sub chkreflash()
dim ScriptName
ScriptName=lcase(request.ServerVariables("PATH_INFO"))
dim posttime,DoReflashPage,ReflashPage,SplitReflashPage
posttime=1 '防止重新整理時間
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 for
end if
next
if (not isnull(session("ReflashTime"))) and posttime>0 and DoReflashPage then
if DateDiff("s",session("ReflashTime"),Now())<posttime then
call msg("警告!系統已記錄您的IP,和重新整理次數。\n\n請不要在"&posttime&"秒內連續重新整理本頁面!","-1")
else
session("ReflashTime")=Now()
end if
elseif isnull(session("ReflashTime")) and posttime>0 and DoReflashPage then
Session("ReflashTime")=Now()
end if
End Sub
調用方法在頁面首部加入chkreflash即可