MyBB Community Forums

Full Version: View Counts on Threads
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have a small forum, but the number of views is very high on the topics and there are always guest visitors, which I believe must be search engines driving up the view count, maybe?

Is there a way to only have the number of views for topics show for real visitors clicking on and reading the thread?

I would like to get a real idea of what topics get the most readers.

Thanks

1. Open the ./showthread.php file in a text editor.

2. Find: (around line 640)

// Increment the thread view.
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}'");
}
++$thread['views'];

3. Replace with:

// Increment the thread view.
if($mybb->user['usergroup'] != 1)
{
	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}'");
	}
	++$thread['views'];
}

4. Save and re-upload the ./showthread.php file.
Thanks...
So that will stop the bots being recorded as page views?
Not quite, it will stop all guests (i.e. unregistered users) from being recorded as page views.
You could use $session->is_spider, but that would only work for known spiders and bots (Those listed in the admin cp).
(2011-12-22, 05:58 PM)Nathan Malcolm Wrote: [ -> ]You could use $session->is_spider, but that would only work for known spiders and bots (Those listed in the admin cp).

Where exactly would I put the $session->is_spider in the file?

Thanks

In the above code, replace:

if($mybb->user['usergroup'] != 1)

with:

if($mybb->user['usergroup'] != 1 && $session->is_spider == false)