有时我们要限制用户重复刷新一个页面。很多站点对于录入操作都用验证码来限制恶意灌水。但是如果是在一套web管理系统中,执行一段没有界面的逻辑操作代码时,就不能用验证码了。我们一般用session来限制。下面就是一个包装的函数,用法很简单。
'操作限制函数 '塞北的雪 制作 'SessionName session的名字 'SecondSpan 时间间隔(单位:秒) function CanDoRepeat(SessionName,SecondSpan) xx=timer() if session(SessionName)= then session(SessionName)=xx else if xx-session(SessionName)<SecondSpan then CanDoRepeat=false else session(SessionName)=xx CanDoRepeat=true end if end if end function
if CanDoRepeat(northsnow_100,100) then
要执行的程序
end if
或者
将下面代码放到程序的首部 if not CanDoRepeat(northsnow_100,100) then
Response.end
end if
这样就可以限制这个程序在一百秒之内只能执行一次
|