ASP prevent Refresh function Implementation code _ Application Skills

Source: Internet
Author: User
Tags servervariables time interval
Instructions for use
1. Add the reference to the antirefresh.asp file at the top of the page you want to protect, such as:
<!--#include virtual= "antirefresh.asp"-->
2. Then add the calling code
Copy Code code 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 ' time interval
If not objantirefresh.isvalidaccess () Then
Set objantirefresh=nothing
Response.Write ("Your visit used to take 2 seconds to try again.")
Response.End ()
End If
Set objantirefresh=nothing
%>

One of the things to note is that
Const varnamedatearr= "Www_domai_net_app_dataarr" queue name
Const varnameiparr= "Www_domai_net_app_iparr" queue name
For example, if you want to add a list.asp to the search.asp, then you copy the calling code to these two pages, or you guarantee that two pages will fall in line with the code. The effect is that you visit the List.asp page so you won't be able to access list.asp or search.asp pages in 2 seconds.
If you want 2 pages independent, that is, you visit the list.asp, you will not be able to visit list.asp in 2 seconds, but you can visit the Search.asp, and then you have to guarantee 2 pages of the Const varnamedatearr= "xxx", Const varnameiparr= "xxx" different, for example, the first also face you use xxxlist, the page with Xxxsearch,
Such as:
Const varnamedatearr= "Www_domai_net_app_dataarr_search" (_list)
Const varnameiparr= "Www_domai_net_app_iparr_search" (_list)
Nagging these are for the less-understood friends so that they can use the code, and if you know more about ASP then it's good for you to understand.
Below is the antirefresh.asp file source code
Copy Code code 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 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 prevents refreshing
Copy Code code as follows:

Sub Chkreflash ()
Dim scriptname
Scriptname=lcase (Request. ServerVariables ("Path_info"))
Dim posttime,doreflashpage,reflashpage,splitreflashpage
Posttime=1 ' Prevent 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 For
End If
Next
if (Not IsNull ("Reflashtime")) and posttime>0 and Doreflashpage then
If DateDiff ("s", Session ("Reflashtime"), Now ()) <posttime Then
Call MSG ("Warning!") The system has recorded your IP, and the number of refreshes. \ n \ nplease 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

Call method to add Chkreflash to page header
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.