Discuz論壇添加虛擬會員、虛擬遊客(根據實際會員遊客數)

需求:論壇添加虛擬會員、虛擬遊客,公式爲
虛擬會員 =(實際會員*10,實際會員*10+10)-------->(最小值,最大值)
虛擬遊客 =(實際遊客*10,實際遊客*10+10)

修改代碼:
bbs/include/index_classics.inc.php:
$discuz_action = 1;後添加以下代碼
//=========================================================================================
//虛擬在線會員+遊客 START

$virtualhack = '1'; // 1=開 0=關

if($virtualhack=='1') {

$mintime = 100; // 在線的最小值(秒)
$maxtime = 600; // 在線的最大值(秒)
$dis_time = 610; // 超過dis_time(秒)刪除

$current_user = 100; // 當前用戶少於100,就執行虛擬用戶

$start_uid = 3; // 起始會員UID
$end_uid = 1000; // 結束會員UID

$action_arr = array("0","0","1","1","2","191","1","2","2","2","31","51"); //設定虛擬用戶允許動作

$current = time();
$current_different = $current - $dis_time;

$query = $db -> query("SELECT COUNT(*) FROM {$tablepre}sessions WHERE ip1<>'000'");
$onlineuser = $db -> result($query, 0);
$membercountsession = $db->result_first("SELECT COUNT(*) FROM {$tablepre}sessions WHERE uid <> '0' and ip1<>'000'");
$guestcountsession = $onlineuser-$membercountsession;

$min_user = $membercountsession*9; // 設定想增加多少會員的最小值
$max_user = $membercountsession*10; // 設定想增加多少會員的最大值

$min_guest = $guestcountsession*9; // 設定想增加多少訪客的最小值
$max_guest = $guestcountsession*10; // 設定想增加多少訪客的最大值

if($onlineuser <= $current_user ) {
$db -> query("DELETE FROM {$tablepre}sessions WHERE ip1='000'");
$randguest = mt_rand($min_guest, $max_guest); //遊客
$randuser = mt_rand($min_user, $max_user); //會員

$query = $db -> query("SELECT fid FROM {$tablepre}forums WHERE type = 'forum'");
while($fidresult = $db -> fetch_array($query)) {
$fidscope[] = $fidresult['fid'];
}

// 隨機插入在線會員
for($i = 1; $i <= $randuser; $i++) {

$randtime = mt_rand($mintime, $maxtime);
$onlinetime = $current - $randtime;

$randaction = mt_rand(0, count($action_arr));
$onlineaction = $action_arr[$randaction];

$onlinefid = 0;
if($onlineaction == '2') {
$randfid = mt_rand(0, count($fidscope));
$onlinefid = $fidscope[$randfid];
}
$online_sid = random(6);


$rand_uid = mt_rand($start_uid, $end_uid);
$query = $db -> query("SELECT `uid`,`username` FROM {$tablepre}members WHERE `uid` = '$rand_uid'");
while($row = $db -> fetch_array($query)){
$db -> query("INSERT INTO {$tablepre}sessions (sid,ip1, groupid, styleid, lastactivity, action, fid, uid, username )
VALUES ('$online_sid','000' ,'10', '1','$onlinetime','$onlineaction','$onlinefid','$row[uid]','$row[username]')");
}
}

// 隨機插入在線遊客
for($i = 1; $i <= $randguest; $i++) {
$randtime = mt_rand($mintime, $maxtime);
$onlinetime = $current - $randtime;

$randaction = mt_rand(0,count($action_arr));
$onlineaction = $action_arr[$randaction];

$onlinefid = 0;
if($onlineaction == '2') {
$randfid = mt_rand(0,count($fidscope));
$onlinefid = $fidscope[$randfid];
}
$online_sid = random(6);
$db -> query("INSERT INTO {$tablepre}sessions (sid,ip1, groupid, styleid, lastactivity, action, fid )
VALUES ('$online_sid','000' ,'7', '1','$onlinetime','$onlineaction','$onlinefid')");
}


}
}

//虛擬在線會員+遊客 END
//=========================================================================================
發佈了24 篇原創文章 · 獲贊 1 · 訪問量 5萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章