使用說明
1.在要保護(hù)的頁面頂部加如對AntiRefresh.asp文件的引用如:
!--#include virtual="AntiRefresh.asp" -->
2.接著添加調(diào)用代碼
復(fù)制代碼 代碼如下:
%
Const VarNameDateArr="www_domai_net_App_DataArr" '隊(duì)列名稱
Const VarNameIPArr="www_domai_net_App_IPArr" '隊(duì)列名稱
Dim objAntiRefresh
Set objAntiRefresh= new AntiRefresh
objAntiRefresh.BufferSize=100 '隊(duì)列大小
objAntiRefresh.CacheItemAvailTime=2 '間隔時(shí)間
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" '隊(duì)列名稱
Const VarNameIPArr="www_domai_net_App_IPArr" '隊(duì)列名稱
比方你要在List.asp與search.asp中加入通一個(gè)防刷新器,那么你把上面的調(diào)用代碼分別復(fù)制到這兩個(gè)頁面,或者保證兩個(gè)頁面的掉用代碼一致。這樣的效果是,你訪問了List.asp頁那么你在2秒內(nèi)將不能訪問List.asp或Search.asp頁
如果你要2個(gè)頁面獨(dú)立,即你訪問List.asp后,你會在2秒內(nèi)不能再次訪問List.asp,但是你可以訪問Search.asp,反之毅然,那么你就要保證2個(gè)頁面的 Const VarNameDateArr="xxx",Const VarNameIPArr="xxx"不同,比方第一個(gè)也面你用xxxList,第個(gè)個(gè)頁面用xxxSearch,
如:
Const VarNameDateArr="www_domai_net_App_DataArr_Search" '(_List)
Const VarNameIPArr="www_domai_net_App_IPArr_Search" '(_List)
嘮叨這些是給那么不太懂的朋友,以便他們能使用這些代碼,如果你懂Asp那么以上的對你來說就很好理解了。
下面是AntiRefresh.asp文件源碼
復(fù)制代碼 代碼如下:
%
'***************************************
'* 頁面防刷新模塊 *
'* 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防止刷新
復(fù)制代碼 代碼如下:
Sub chkreflash()
dim ScriptName
ScriptName=lcase(request.ServerVariables("PATH_INFO"))
dim posttime,DoReflashPage,ReflashPage,SplitReflashPage
posttime=1 '防止刷新時(shí)間
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("警告!系統(tǒng)已記錄您的IP,和刷新次數(shù)。\n\n請不要在"posttime"秒內(nèi)連續(xù)刷新本頁面!","-1")
else
session("ReflashTime")=Now()
end if
elseif isnull(session("ReflashTime")) and posttime>0 and DoReflashPage then
Session("ReflashTime")=Now()
end if
End Sub
調(diào)用方法在頁面首部加入chkreflash即可
您可能感興趣的文章:- ASP.Net防止刷新自動觸發(fā)事件的解決方案
- 用Asp如何實(shí)現(xiàn)防止網(wǎng)頁頻繁刷新?
- ASP.Net中防止刷新自動觸發(fā)事件的解決方案
- asp.net防止刷新時(shí)重復(fù)提交(可禁用工具條刷新按鈕)
- Asp.Net防止刷新重復(fù)提交數(shù)據(jù)的辦法
- ASP.NET防止頁面刷新的兩種解決方法小結(jié)
- php環(huán)境下利用session防止頁面重復(fù)刷新的具體實(shí)現(xiàn)
- php防止網(wǎng)站被刷新的方法匯總
- PHP防止刷新重復(fù)提交頁面的示例代碼
- php采用session實(shí)現(xiàn)防止頁面重復(fù)刷新
- ASP.NET中防止頁面刷新造成表單重復(fù)提交執(zhí)行兩次操作