asp阻止灌水留言的一个方法(随机生成的4位认证码)

2008-10-18 0:12:00查看学习心得

原理:在每次提交留言的时候,要输入随机生成的4位认证码.

以下代码用在ASP
生成随机4位数:

<%
dim key
randomize timer
key=Int((8999)*Rnd +1000)
%>

在表单里显示:

认证码:<%=key%>
<input type="text" name="rekey" size="8" maxlength="4">
<input value="<%=key%> " type="hidden" name="key">

表单提交后检查:

key=Request.Form("key")
rekey=Request.Form("rekey")
if rekey<> key then
Response.Write("<script language=javascript> alert('请输入正确的认证码!');history.back()</script> ")
response.End()
end if

本文来源:http://www.code-123.com/wlbc/asp/list_1.html 转载请保留!

本文作者:
页面收藏到: [收藏到QQ书签] [新浪ViVi] [Poco] [bbmao] [365KEY] [天极网摘] [我摘] 点击复制本页地址,传给QQ/MSN上的好友
更多»学习心得

笔名  匿名  
Email