MyBB Community Forums

Full Version: How do I disable bot views?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
On my board I only have 3 members but on every thread there are 70 to 100 views. I think that I know the problem. I think when the bots navigate the board it is registering the views from them which is making the view skyrocket! How do I disable this?
It'll require a core edit. I wrote a tutorial for it a few years ago but I can't seem to find it back. Luckily I still have it on my hard drive.

Open showthread.php with a text editor, find:

if($mybb->settings['delayedthreadviews'] == 1)
{
$db->shutdown_query("INSERT INTO ".TABLE_PREFIX."threadviews (tid) VALUES('{$tid}')");
}
else
{
$db->shutdown_query("UPDATE ".TABLE_PREFIX."threads SET views=views+1 WHERE tid='{$tid}'");
}

and replace with:

if($mybb->settings['delayedthreadviews'] == 1 && $session->is_spider == false)
{
$db->shutdown_query("INSERT INTO ".TABLE_PREFIX."threadviews (tid) VALUES('{$tid}')");
}
elseif($session->is_spider == false)
{
$db->shutdown_query("UPDATE ".TABLE_PREFIX."threads SET views=views+1 WHERE tid='{$tid}'");
}
Nice one, so guests will not affect the view counter, thanks for it.
(2012-07-09, 09:49 PM)Omar G. Wrote: [ -> ]Nice one, so guests will not affect the view counter, thanks for it.

Guests will, spiders which are on the spiders and bots list won't. Smile
Oh, you are right ... suppose that will be enough then. Guests are "real" members compared to spiders. Still going to use it.
Thank you for the reply. I did the code edit!
If you don't want thread authors to increase the threa views count as well, use this instead of Nathan's code:
if(!$session->is_spider && $mybb->user['uid'] != $thread['uid'])
{
	if($mybb->settings['delayedthreadviews'])
	{
		$db->shutdown_query("INSERT INTO ".TABLE_PREFIX."threadviews (tid) VALUES('{$tid}')");
	}
	else
	{
		$db->shutdown_query("UPDATE ".TABLE_PREFIX."threads SET views=views+1 WHERE tid='{$tid}'");
	}
}
thanks for the answers! this could be a new feature for new versions, no?