防止重复提交的子程序Asp版本
发表于:2007-06-30来源:作者:点击数:
标签:
此为CGI子程序的一个Asp改编版本,其中使用FileSystemObject对象中的TextStream对象的ReadAll方法。因此,需要定期清理记录文件floodcheck.ini。以免影响速度。该处理方法的一个好处是留有Post者的ip地址记录并且能应用于不同类型的系统。(只要在您的处理代
此为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原代码 摘自经典
论坛
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);
foreach (@last_post_list)
{ # check if this user has posted a
lready
if (/^$IPNumber/){
($junk,$last_post_time) = split(/\|!!\|/,$_);
chomp($last_post_time);
last;
}
} # end foreach
$wait_between_posts *= 60; # convert wait_between_posts to seconds
if ( int(($this_post_time - $last_post_time) < $wait_between_posts))
{
&StandardHTML("抱歉,您刚刚发表过一篇文章,为了避免重复发表,请稍候返回$wait_between_posts秒再发表您的文章.");
exit;
}
else
{ # add the IP and posting time to the list
if (unshift(@last_post_list, "$IPNumber|!!|$this_post_time\n") > $lastpost_list_length)
{
$#last_post_list = $lastpost_list_length; # limit length of list
}
open(LASTPOST, ">$NonCGIPath/BanLists/Floodcheck.cgi") | | die(&StandardHTML("错误$!"));
print LASTPOST @last_post_list;
close(LASTPOST);
} # end else
return 1;
原文转自:http://www.ltesting.net