给问题加一个自动清理垃圾问题的方法
你的网站是不是也被灌水机攻击了,删问题删的手软,以下方法可以让它自动清理:
1、禁止灌水发提问的用户(这是关键)
2、在程序目录下的 models\question.php 代码最下面 } 前添加:
public function delete_user_question()
{
if (AWS_APP::cache()->get('delete_question_num')) {
return false;
}
$uids = $ids = array();
if (! $uids = AWS_APP::cache()->get('delete_user_question')) {
$time = time() - 86400 * 90;
foreach($this->fetch_all('users', 'reg_time>' . $time . ' AND integral>100 AND forbidden>0', '', null, 1000) as $value) {
$uids[] = $value['uid'];
}
AWS_APP::cache()->set('delete_user_question', $uids, 86400);
}
if ($question = $this->fetch_all('question', "published_uid IN(" . implode(',', $uids) . ")", '', 1000))
{
foreach($question as $key => $value) {
$ids[] = $value['question_id'];
$this->remove_question($value['question_id']);
}
if (($num = count($ids)) <= 0) {
AWS_APP::cache()->set('delete_question_num', 100);
}
}
}
3、在计划任务里添加 models\crond.php
// 每半分钟执行 或 // 每分钟执行 或自行选择周期
$this->model('question')->delete_user_question();
2019-07-14 18:04
2019-07-09 19:56
2019-07-09 12:43
2019-07-01 20:26