The Arcive of vBulletin Modifications Site. |
|
|
#1
|
|||
|
|||
|
In vb 3.8.4, what do you think would be the easiest/simplest way to make it so that the thread view count is only incremented for each unique user? In other words, hitting refresh on a thread page wouldn't increment the count, unless the user changed IP's.
Would I need to maintain a database of IP's and check the table before incrementing the count, or is there a simpler way? I could use cookies to do it, but if someone disabled their cookies, then they could just increment the count at will. Nevermind I decided to just code it. This goes in showthread.php around line 489 replacing the existing views counter code. Code:
$userip = $_SERVER[REMOTE_ADDR];
$ipnum = ip_address_to_number($userip);
$getuip = $db->query_first("
SELECT count(*) as views
FROM ipchecker
WHERE threadid = ".intval($threadinfo['threadid'])." AND ipaddr=".$ipnum
);
if ($getuip['views'] <=1) {
if ($vbulletin->options['threadviewslive'])
{
// doing it as they happen; for optimization purposes, this cannot use a DM!
$db->shutdown_query("
UPDATE " . TABLE_PREFIX . "thread
SET views = views + 1
WHERE threadid = " . intval($threadinfo['threadid'])
);
}
else
{
// or doing it once an hour
$db->shutdown_query("
INSERT INTO " . TABLE_PREFIX . "threadviews (threadid)
VALUES (" . intval($threadinfo['threadid']) . ')'
);
$db->shutdown_query("
INSERT INTO ipchecker VALUES (NULL,".time().",".$ipnum.",".intval($threadinfo['threadid']).')'
);
}
}
function ip_address_to_number($IPaddress)
{
if ($IPaddress == "") {
return 0;
} else {
$ips = split ("\.", "$IPaddress");
return ($ips[3] + $ips[2] * 256 + $ips[1] * 256 * 256 + $ips[0] * 256 * 256 * 256);
}
}
Quote:
|
![]() |
|
|
| X vBulletin 3.8.12 by vBS Debug Information | |
|---|---|
|
|
More Information |
|
|
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|