防止短时间重复提交留言!
代码
session("time")=now()
const a=#0:0:60# '定义相隔之间的秒数
if session("time2") >0 then '如果有值
if session("time2")+a > session("time") then '
session("time2")=now()
response.Write "<script language=javascript> {window.alert('为防止恶意灌水,请您20秒后再留言,谢谢!');window.history.go(-1);}</script>"
response.end
end if
end if
session("time2")=now()
我的留言板的脚本代码
<%
if request("send")="ok" then
username=trim(request.form("username"))
usermail=trim(request.form("usermail"))
if request.form("usermail") <> "" then '邮箱为必填时检查邮箱是否合法
if checktxt(request.form("usermail"))<>request.form("usermail") then
response.write "<script language='javascript'>"
response.write "alert('您输入的邮箱中含有非法字符,请检查后重新输入!');"
response.write "location.href='javascript:history.go(-1)';"
response.write "</script>"
response.end
end if
if Instr(usermail,".")<=0 or Instr(usermail,"@")<=0 or len(usermail)<10 or len(usermail)>50 then
response.write "<script language='javascript'>"
response.write "alert('您输入的电子邮件地址格式不正确,请检查后重新输入!');"
response.write "location.href='javascript:history.go(-1)';"
response.write "</script>"
response.end
end if
end if
if len(request.form("Comments"))>maxlength then
response.write "<script language='javascript'>"
response.write "alert('留言内容太长了,请不要超过"&maxlength&"个字符!');"
response.write "location.href='javascript:history.go(-1)';"
response.write "</script>"
response.end
end if
set rs=Server.CreateObject("ADODB.RecordSet")
sql="select * from BookFeedBack where online='1' order by Postdate desc"
rs.open sql,conn,1,3
rs.Addnew
rs("username")=Request("username")
rs("comments")=Request("comments")
rs("usermail")=Request("usermail")
rs("face")=Request("face")
rs("pic")=Request("pic")
rs("url")=Request("url")
rs("qq")=Request("qq")
view=cstr(view)
if view<>"0" then view="1"
rs("online")=view
rs("IP")=Request.serverVariables("REMOTE_ADDR")
rs.Update
rs.close
set rs=nothing
response.write "<script language='javascript'>"
if view="0" then
response.write "alert('留言提交成功,留言须经管理员审核才能发布。');"
else
response.write "alert('留言提交成功,单击“确定”返回留言列表!');"
end if
response.write "location.href='BookWrite.asp';"
response.write "</script>"
response.end
end if
%>
应该把防止重复提交留言的代码放到哪个位置才行??