琳妈 發表於 2023-8-3 00:00:00

详解织梦模板自定义表单限制IP24小时只能提交一次教程

<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        我们在使用织梦建站的时候会经常碰到织梦dedecms自定义表单功能,方便我们做网站的在线留言,在线下单,在线报名等订单信息提交,我们也发布了( 织梦自定义表单教程 ) 不懂的朋友可以点击看看。但是用户可以无限制重复提交,这样就给网站带来非常高的维护成本,为了防止恶意提交,下面就告诉大家如何设置每个用户24小时内只能提交一次自定义表单:</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        首先我们打开/plus/diy.php文件,在里面找到如下代码:</p>
<div class="jb51code" style='margin: 0px; padding: 0px; outline: none; line-height: 25.2px; font-size: 14px; width: 660px; overflow: hidden; clear: both; font-family: tahoma, arial, "Microsoft YaHei";'>
        <pre class="brush:php;toolbar:false;">
if(!is_array($diyform))
{
showmsg('自定义表单不存在', '-1');
exit();
}
</pre>
</div>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        在其下面添加如下代码:</p>
<div class="jb51code" style='margin: 0px; padding: 0px; outline: none; line-height: 25.2px; font-size: 14px; width: 660px; overflow: hidden; clear: both; font-family: tahoma, arial, "Microsoft YaHei";'>
        <pre class="brush:php;toolbar:false;">
//检测游客
if(isset($_COOKIE['VOTE_MEMBER_IP']))
{
if($_COOKIE['VOTE_MEMBER_IP'] == $_SERVER['REMOTE_ADDR'])
{
ShowMsg('您已经填写过表单啦','-1');
exit();
} else {
setcookie('VOTE_MEMBER_IP',$_SERVER['REMOTE_ADDR'],time()*$row['spec']*3600,'/');
}
} else {
setcookie('VOTE_MEMBER_IP',$_SERVER['REMOTE_ADDR'],time()*$row['spec']*3600,'/');
}
</pre>
</div>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        点评:添加完成后保存覆盖原来的就可以了,此方法是通过验证cookie的方式防止用户重复提交,如果用户清除cookie的话还是可以提交的。</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。</p>
頁: [1]
查看完整版本: 详解织梦模板自定义表单限制IP24小时只能提交一次教程