【asp】有效防止网站留言板出现垃圾留言/评论实现思路_ASP教程

一.在表单填写页面: ”>
在提交处理页面,设置提交时间
代码如下:
If DateDiff(“s”,request.form(“intime1”), Now()) < 5 then
response.write “alert('您的留言速度太快,禁止留言!');"

response.end
end if

二.验证码
代码如下:
yz=cstr(request.Form(“yz”))
yz1=cstr(session(“yz1”))
if yz1<>yz then
Response.Write(““)
response.redirect(“sign.asp”)
end if

三.判断来路
代码如下:
server_v1=Cstr(Request.ServerVariables(“HTTP_REFERER”))
‘Response.Write(server_v1)
server_v2=Cstr(Request.ServerVariables(“SERVER_NAME”))
‘Response.Write(server_v2)
if mid(server_v1,8,len(server_v2))<>server_v2 then
Response.Write(““)
response.end
end if

四.设置每日提交次数
代码如下:
‘当用户每提交一次
if request.cookies(“postnum”)=”” then
response.cookies(“postnum”)=1
response.cookies(“postnum”).expires=DateAdd(“h”, 24, Now())
else
response.cookies(“postnum”)=request.cookies(“postnum”)+1
end if
if request.cookies(“postnum”) > 3 then
response.write “alert('今天留言次数超过限制,禁止留言!');"

response.end
end if

五.禁止IP
代码如下:
server_ip=Cstr(Request.ServerVariables(“REMOTE_ADDR”))
if right(server_ip,8) = “194.165.” then
response.write “禁止重叠提交194.165.”
response.End()
end if

1、判断该发布信息是否有可靠的来路。只要是自然人发布的,那么他一定是通过我们提供给用户的提交页过来的,一定有一个来路;如果是机器发布的,就不会有来路信息。
‘判断来路,禁止外部提交
代码如下:
dim server_v1,server_v2
server_v1=Cstr(Request.ServerVariables(“HTTP_REFERER”))
server_v2=Cstr(Request.ServerVariables(“SERVER_NAME”))
if server_v1=”” or instr(server_v1,”/add.asp”)<=0 or mid(server_v1,8,len(server_v2))<>server_v2 then
response.write “alert('来源非法,禁止外部提交!');"

response.end
end if

注意,上面的/add.asp就是提交页面来源页。当然,机器也可以伪造来路,这就要结合以下方式一起对付了。
2、验证码。验证码一直是对付机器垃圾留言的一个可行的方法。不同的验证码有不同的对付机器留言的能力,越复杂的验证码,机器越难破解。这需要在考虑用户的感受和对付机器之间选择一个平衡点。关于验证码的使用方法,我就不多说了,谷歌、百度里搜索下就会出现很多介绍。
3、判断来源提交的时间。如果在提交页停留的时间太短,比如20秒,一般只要是个人,他打字的时间都不必这个少。举例说明,在用户打开页面(如add.asp)的时候,我们记下这个时间,在form提交表单里增加一个隐藏对象,如:
”>
然后,当用户写好留言评论后提交到具体处理页面(如addok.asp)的时候,我们获取当前时间,和add.asp里的这个intime1时间比较,如果这个时间差小于设定的时间,如20秒,则禁止留言,判断为机器。代码可这样写:
代码如下:
If DateDiff(“s”,request.form(“intime1”), Now()) < 20 then
response.write “alert('您的留言速度太快了吧,禁止留言!');"

response.end
end if

通过以上三种方法可以屏蔽掉绝大部分的机器垃圾留言评论,如果还有大量的留言的话,那多半是人肉留言了。但是,我们又如何对付人肉留言呢?flymorn也提供方法对付。
方法很简单,就是通过记录用户的cookies以及IP来限制同一用户发表留言的数量。比如一天24小时内,只允许同一用户发表信息5条。我们可以通过以下方法实现。
代码如下:
<%’当用户每提交一次
if request.cookies(“postnum”)=”” then
response.cookies(“postnum”)=1
response.cookies(“postnum”).expires=DateAdd(“h”, 24, Now())
else
response.cookies(“postnum”)=request.cookies(“postnum”)+1
end if
if request.cookies(“postnum”) > 5 then
response.write “alert('今天留言次数超过限制,禁止留言!');"

response.end
end if
%>

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
WordPress屏蔽国外垃圾留言评论,将文件里的代码放到当前主题的 functions.php 中; 的前面就可以了。代码参考:https://boke112.com/bkwd/4209.html 和https://loomob.com/57.html 将以下代码放到当前主题的 functions.php 文件最后一个 ?> 的前面: //防国外灌水 function scp_comment_post( $incoming_comment ) { // 禁止全英文评论 $pattern = '/[x7f-xff]/'; if(!preg_match($pattern, $incoming_comment['comment_content'])) { wp_die( "您的评论中必须包含汉字! <br /> You should type some Chinese word (like "你好") in your comment to pass the spam-check, thanks for your patience! " ); } //禁止 A 链接 if(strstr($incoming_comment['comment_content'], "<a")){ wp_die( "您的评论中不能有 A 链接,请直接填写 URL 地址" ); } // 判断 中文字符占比 $len_all = strlen($incoming_comment['comment_content']); $len_st = mb_strlen($incoming_comment['comment_content'], 'UTF-8'); if(($len_all-$len_st)/(2*$len_st) < 0.5){ wp_die( "中文字符少于百分之五十" ); } return( $incoming_comment ); } add_filter('preprocess_comment', 'scp_comment_post'); //屏蔽关键词,email,url,ip function Shield_fuckspam($comment) { if (wp_blacklist_check($comment['comment_author'], $comment['comment_author_email'], $comment['comment_author_url'], $comment['comment_content'], $comment['comment_author_IP'], $comment['comment_agent'])) { header("Content-type: text/html; charset=utf-8"); err(__('不好意思,您的评论违反画里网站评论规则')); } else { return $comment; } } add_filter('preprocess_comment', 'Shield_fuckspam'); //过滤外文评论 function refused_spam_comments($comment_data) { $pattern = '/[一-龥]/u'; $jpattern = '/[ぁ-ん]+|[ァ-ヴ]+/u'; if (!preg_match($pattern, $comment_data['comment_content'])) { err(__('来一波汉字吧,博主只认识汉字!You should type some Chinese word!')); } if (preg_match($jpattern, $comment_data['comment_content'])) { err(__('原谅博主吧,只听得懂岛国神片的一两句雅蠛蝶 Japanese Get out!日本语出て行け! You should type some Chinese word!')); } return ($comment_data); } add_filter('preprocess_comment', 'refused_spam_comments'); //屏蔽带连接的 function Shield_link($comment_data) { $links = '/http:\/\/|https:\/\/|www\./u'; if (preg_match($links, $comment_data['comment_author']) || preg_match($links, $comment_data['comment_content'])) { err(__('别啊,昵称和评论里面添加链接会怀孕的哟!!')); } return ($comment_data); } add_filter('preprocess_comment', 'Shield_link');

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值