在使用织梦cms建网站的时候,有时候为了较少服务器的压力或者防止一些会员恶意下载,就需要对会员每天的下载次数做限制,那么如何实现这个功能呢?下面织梦58小编带您一步步操作:
1、首先在后台的数据库备份/还原地方做一个数据库备份,因为接下来要执行几个sql文件,做好数据备份以免出现未知错误。
2、建立dede_xiazai这个数据库表,执行以下sql:1CREATE TABLE `dede_xiazai` (2 `mid` int(11) NOT NULL,3 `aid` int(11) NOT NULL,4 `mtime` int(11) NOT NULL5) ENGINE=MyISAM DEFAULT CHARSET=latin1;
3、在原数据库表dede_arcrank内增加两个字段 daydowns hourdowns 分别为 每天限制次数 每日限制次数,在这里默认是10次,大家可以按照自己的需求更改这个次数:DEFAULT '10'1ALTER TABLE `dede_arcrank` ADD `daydowns` INT(6) NOT NULL DEFAULT '10' AFTER `purviews`, ADD `hourdowns` INT(6) NOT NULL DEFAULT '10' AFTER `daydowns`;
4、找到plus文件夹下的download.php文件在191行插入:01//获取用户级别//02 $rank = $dsql->GetOne("SELECT rank FROM `dede_member` WHERE mid='" . $cfg_ml->M_ID . "'");03 $level = $dsql->GetOne("SELECT membername,daydowns,hourdowns FROM `dede_arcrank` WHERE rank='" . $rank['rank'] . "'");04 //查询下载次数,限制下载次数//05 $row = $dsql->GetOne("SELECT COUNT(mid) FROM `dede_xiazai` WHERE mid='" . $cfg_ml->M_ID . "' AND to_days(curdate())=to_days(from_unixtime(mtime))");06 $daycishu = $row['COUNT(mid)'];07 $date = date("Y-m-d H:00", time());08 $hour = strtotime($date);09 $row2 = $dsql->GetOne("SELECT COUNT(mid) FROM `dede_xiazai` WHERE mid='" . $cfg_ml->M_ID . "' AND mtime >= '" . $hour . "'");10 $hourcishu = $row2['COUNT(mid)'];11 if ($level['daydowns'] != 0) {12 if ($daycishu >= $level['daydowns']) {13 $errtype = 3;14 $moremsg = $level['membername'] . "24小时内最多能下载" . $level['daydowns'] . "个资源,您的下载次数已到达" . $daycishu . "次";15 include_once (DEDETEMPLATE . '/plus/view_msg.htm');16 exit(0);17 }18 }19 if ($level['hourdowns'] != 0) {20 if ($hourcishu >= $level['hourdowns']) {21 $errtype = 3;22 $moremsg = $level['membername'] . "1小时内最多能下载" . $level['hourdowns'] . "个资源,您的下载次数已到达" . $hourcishu . "次";23 include_once (DEDETEMPLATE . '/plus/view_msg.htm');24 exit(0);25 }26 }27//用户为注册会员以上级别,做下载次数记录////28if ($cfg_ml->M_Rank >= 10) {29//下载次数记录30$inquery = "INSERT INTO `dede_xiazai`(mid,mtime,aid) VALUES ('" . $cfg_ml->M_ID . "','" . time() . "','.$id.'); ";31//记录定单32if (!$dsql->ExecuteNoneQuery($inquery)) {33ShowMsg('记录定单失败, 请返回', '-1');34exit(0);35}