标题: ASP教程之避免反复提交的子法式Asp版本 [打印本页] 作者: 逍遥一派 时间: 2015-2-3 23:38 标题: ASP教程之避免反复提交的子法式Asp版本 ASP脚本是采用明文(plain text)方式来编写的。法式|反复|反复提交 此为CGI子法式的一个Asp改编版本,个中利用FileSystemObject对象中的TextStream对象的ReadAll办法。因而,需求按期清算纪录文件floodcheck.ini。以避免影响速度。该处置办法的一个优点是留有Post者的ip地址纪录而且能使用于分歧类型的体系。(只需在您的处置代码处用Response.Redirect "你的处置Post Asp页")就能够了。 我改编的Asp代码
<%
'避免反复提交的asp代码
'floodcheck.ini文件格局
'最初宣布工夫|IP地址
'变量声明
'两个Post距离工夫,以分为单元
Dim Wait_between_Post
'发贴者IP地址
dim IPNumber
'本次Post工夫
Dim This_Post_Time
'前次Post工夫
Dim Last_Post_Time
Wait_between_Post=0.1
This_Post_time=Now
IPNumber=Request.ServerVariables("REMOTE_ADDR")
dim fso
Set fso=CreateObject("Scripting.FileSystemObject")
'1 forReading
Set f=fso.OpenTextFile("floodcheck.ini",1,true)
if f.atEndOfStream then
f.close
'2 forWritting
Set f=fso.OpenTextFile("floodcheck.ini",2,true)
f.WriteLine(this_Post_Time & "|" & IPNumber)
f.close
Set fso=Nothing
'交换成您的处置代码
response.write "转到到Post处置页或处置代码"
response.end
'交换成您的处置代码
else
dim PostRec
dim varTemp
PostRec=f.ReadAll
f.close
dim objRegExp
Set objRegExp=new RegExp
objRegExp.Pattern=".+|" & IPNumber & ""
objRegExp.Global = True
Set objMatches = objRegexp.Execute(PostRec)
for each objMatch in objMatches
varTemp=split(objMatch.Value,"|")
last_post_time=cdate(varTemp(0))
if dateadd("s",wait_between_post*60,last_post_time)>this_post_time then '转化为秒
set fso=nothing
'交换成您的处置代码
response.write "抱愧,您方才宣布过一篇文章,为了不反复宣布,请稍候前往" & wait_between_post & "分钟再宣布您的文章."
response.end
'交换成您的处置代码
end if
next
'8 forAppending
Set f=fso.OpenTextFile("floodcheck.ini",8,true)
f.WriteLine(this_Post_Time & "|" & IPNumber)
f.close
set fso=nothing
'交换成您的处置代码
response.write "转到到Post处置页或处置代码"
response.end
'交换成您的处置代码
end if
%> CGI原代码 摘自经典服装论坛http://202.106.124.52/zmy/ubb/Ultimate.cgi?action=intro
sub floodcheck
{ # blocks multiple posting in a short period
$wait_between_posts = "0.2"; # edit in the default number of minutes to wait
$lastpost_list_length = 15; # edit in the number of records to keep
my $IPNumber = $ENV{'REMOTE_ADDR'}; # the IP address
my $this_post_time = time(); # secs since 1970
open(LASTPOST, "$NonCGIPath/BanLists/Floodcheck.cgi"); # don't bother with error code if it doesn't exist
@last_post_list = <LASTPOST>;
close(LASTPOST);