PDA

View Full Version : Visitor Totals Last 24hrs


tcs
11-12-2005, 10:00 PM
ported for 3.5.x.

It's a cool hack if you like to look at your total hits in a 24hr day from both members and guests.

1 PHP Modification to includes/cleanup.php
1 Template Mod. to Forumhome
1 Product Pluggin

Instructions and XML are in the zip.

I will support this hack but should be much trouble with it. Been running it since vB 2.2 I think.

When you first install this hack it will only track from the time the last sessions cleanup was completed. After a sessions cleanup it will start over or reset to 1hr again. Then track the hours in increments for 24hrs. Then clean out the sessions table and start over again. Sessions cleanups should normally occur at midnight.

This hack works if you remove the old code in the cleanup.php and replace it with the new information in the readme.

For information cleanout2.php dose not run hourly like implied in the cron tab. It is set for 5 min after midnight. Jelsoft set it that way and not sure why it is titled a hourly cleanup in the scheduled task. In any event it is needed to reset the script for the next day.

Good luck and I will do my best to answer any questions.

Thanks to Paul M. for pointing out a bug I kept overlooking.

donBLACK
11-13-2005, 12:01 AM
nice

Makaveli105
11-13-2005, 12:15 AM
very nice, thank you :D

TTG
11-13-2005, 12:16 AM
Simple but effective .. thanks
Clicked install

GamerJunk.net
11-13-2005, 01:34 AM
I forced an Hourly CleanUp and got this error...

Parse error: parse error, unexpected ']' in /home/gsnforce/public_html/forum/includes/cron/cleanup.php on line 26

GamerJunk.net
11-13-2005, 01:45 AM
How do I edit it to say 24 hours rather than 1hrs?

It works even with that error.

tcs
11-13-2005, 01:51 AM
Not an error. It counts up to 24 hrs. Check it in another hour.

caliman
11-13-2005, 02:03 AM
I've been waiting for this! Thanks..
Does this use cookies? IP checks? Just curious...

tcs
11-13-2005, 10:19 AM
It uses sessions table in the mysql. It changes the cleanup.php to leave the sessions table alone for 24hrs to collect the data. Then counts userid's and totals them up. Guests are assigned a userid of 0 by vB to be able to separate them from members.

No cookies (Although cookies are made with sessions information) and no IP checks.

bspiller82
11-13-2005, 11:12 AM
I forced an Hourly CleanUp and got this error...

Parse error: parse error, unexpected ']' in /home/gsnforce/public_html/forum/includes/cron/cleanup.php on line 26

I got that error to. Are you saying if you wait an hour then run it, the error will not happen?

Is there a way to change the time from saying last 1 hours to last 24 if it logs the last 24 why have it say last hour?

Snake
11-13-2005, 11:48 AM
Thanks!

lexx27
11-13-2005, 12:47 PM
It worked for the 2 first hours. No it hasnt changed for 2 or 3 hours.

Paul M
11-13-2005, 01:34 PM
It uses sessions table in the mysql. It changes the cleanup.php to leave the sessions table alone for 24hrs to collect the data. Will this screw-up the who's online displays then ?

JTyson
11-13-2005, 01:36 PM
Will this screw-up the who's online displays then ?

Doesnt seem to, http://www.fuo-motorsports.com/forum/

I had to change cleanup2.php aswell

tcs
11-13-2005, 02:26 PM
Will this screw-up the who's online displays then ?

No it will not. Online Sessions are closed and changed by the timeout settings in you admincp.


I got that error to. Are you saying if you wait an hour then run it, the error will not happen?

Is there a way to change the time from saying last 1 hours to last 24 if it logs the last 24 why have it say last hour?


The script will count up to 24hrs. It will track visitor throughout the day.

You change the code to do an hourly cleanup? Leave the cleanup.php original and it will do an hourly cleanup with no additional code changes.

I have never had to mess with cleanup2.php. When you first install this hack it will only track the time from the last sessions cleanup. After a cleanup it will start over or reset to 1hr again.

caliman
11-13-2005, 02:36 PM
tcs ... is there a fix for this? i am holding off because of this error.

Parse error: parse error, unexpected ']' in /home/gsnforce/public_html/forum/includes/cron/cleanup.php on line 26

tcs
11-13-2005, 03:34 PM
Lines 24 to 28 should look like this:

$vbulletin->db->query_write("
DELETE FROM " . TABLE_PREFIX . "session
WHERE lastactivity < " . intval((TIMENOW - 86400]) . "
### Delete stale sessions ###
");


You are looking for a ] extra, missing or out if place.

Post you lines and I will see if I can find it.

JTyson
11-13-2005, 11:45 PM
Lines 24 to 28 should look like this:

$vbulletin->db->query_write("
DELETE FROM " . TABLE_PREFIX . "session
WHERE lastactivity < " . ntval((TIMENOW - 86400]) . "
### Delete stale sessions ###
");


You are looking for a ] extra, missing or out if place.

Post you lines and I will see if I can find it.

Might want to update your readme file as the error is in the code. :)

$vbulletin->db->query_write("
DELETE FROM " . TABLE_PREFIX . "session
WHERE lastactivity < " . intval((TIMENOW - 86400]) . "
### Delete stale sessions ###

tcs
11-14-2005, 02:50 AM
The one in the readme is the correct one. The code on my test site was wrong and had an error I missed.

The code you posted should work fine.

caliman
11-14-2005, 04:41 AM
tcs -

Is this mod compatible with 'who has visited today?'

https://vborg.vbsupport.ru/showthread.php?t=82769

bspiller82
11-14-2005, 05:45 AM
How do I fix mine?


$vbulletin->db->query_write("
DELETE FROM " . TABLE_PREFIX . "cpsession
WHERE dateline < " . intval(TIMENOW - 3600) . "
### Delete stale cpsessions ###


Is giving me this error

Parse error: parse error, unexpected ']' in /home/a247xtre/public_html/forums/includes/cron/cleanup.php on line 26

Paul M
11-14-2005, 09:31 AM
Is this mod compatible with 'who has visited today?'

https://vborg.vbsupport.ru/showthread.php?t=82769I can't see any reason that this would intefere with my hack. :)

caliman
11-14-2005, 12:42 PM
Thanks Paul.

caliman
11-14-2005, 12:48 PM
Hey, mine doesn't seem to work right... if you stay on the site for a while it keeps recounting you as a member and it doesn't seem to go over 1 hour (it's been on past midnight now):

Total users last 1hrs : 13 (10 members and 3 guests)

Any ideas?

lexx27
11-14-2005, 12:58 PM
I have the same problem.

TTG
11-14-2005, 02:06 PM
Hey, mine doesn't seem to work right... if you stay on the site for a while it keeps recounting you as a member and it doesn't seem to go over 1 hour (it's been on past midnight now):

Total users last 1hrs : 13 (10 members and 3 guests)

Any ideas?

Same problem on mine !?

mclark2112
11-14-2005, 06:50 PM
Still a problem in IE in the Dark Blue style...Map is all over the place.

tcs
11-14-2005, 08:05 PM
$vbulletin->db->query_write("
DELETE FROM " . TABLE_PREFIX . "session
WHERE lastactivity < " . intval((TIMENOW - 86400]) . "
### Delete stale sessions ###


Is the code to use in cleanup.php only. Do not change what is in cleanup2.php.

I run "who was online today" and have had no issues or conflicts with them working together.

I just installed this on 3 other boards in an attempt to duplicate this problem. So far they are working fine.

Check your cleanup2.php and make sure you did not change the original code. This is the only hack I know that changes the cleanup.php you can re upload a new copy and try again to see if that fixes it.

amykhar
11-14-2005, 08:33 PM
Typo in the install file.


$vbulletin->db->query_write("
DELETE FROM " . TABLE_PREFIX . "session
WHERE lastactivity < " . intval((TIMENOW - 86400]) . "
### Delete stale sessions ###


Should be

$vbulletin->db->query_write("
DELETE FROM " . TABLE_PREFIX . "session
WHERE lastactivity < " . intval((TIMENOW - 86400)) . "
### Delete stale sessions ###

amykhar
11-14-2005, 08:47 PM
I have NOT been able to test this fully. Or even more than making sure it has no parse errors and the numbers add up. But, here is the plugin code for this mod for those of you using my spider's on the forumhome page.

The forumhome template code needs to change as well. My target audience will know how to do that ;)


$datecut24 = TIMENOW - 86400;
$numberregistered24 = 0;
$numberguest24 = 0;
$numberspiders24 = 0;

$forumusers24 = $vbulletin->db->query("
SELECT userid, lastactivity, useragent FROM " . TABLE_PREFIX . "session
WHERE lastactivity > $datecut24
");

$time24 = TIMENOW ;
while ($loggedin24 = $vbulletin->db->fetch_array($forumusers24))
{
$userid24 = $loggedin24['userid'];
if (!$userid24)
{ // Guest or spider
if (!empty($vbulletin->wol_spiders))
{
if (preg_match('#(' . $vbulletin->wol_spiders['spiderstring'] . ')#si', $loggedin24['useragent'], $agent))
{
$numberspiders24++;
}
else
{
$numberguest24++;
}
}
}
else
{
$numberregistered24++;
}
if ($loggedin24['lastactivity'] < $time24)
{
$time24 = $loggedin24['lastactivity'];
}
}
$time24 = TIMENOW - $time24;
$time24 = floor($time24 / 3600) + (($time24 % 3600) ? 1 : 0);

$numbertotal24 = $numberregistered24 + $numberguest24 +$numberspiders24;

unset($loggedin24);
$vbulletin->db->free_result($forumusers24);

tcs
11-14-2005, 11:22 PM
Typo in the install file.


$vbulletin->db->query_write("
DELETE FROM " . TABLE_PREFIX . "session
WHERE lastactivity < " . intval((TIMENOW - 86400]) . "
### Delete stale sessions ###


Should be

$vbulletin->db->query_write("
DELETE FROM " . TABLE_PREFIX . "session
WHERE lastactivity < " . intval((TIMENOW - 86400)) . "
### Delete stale sessions ###


Thanks, There was a typo on my part. If you have the final spider code input let me know and I will add it and your credits to the install.

Zip file is updated.

amykhar
11-14-2005, 11:54 PM
With this code running, I am having the same error others are reporting. The results are for one hour, even though it's been running for several. I am at work right now and won't be able to analyze the code till later. If I figure out what's amiss, I'll let y'all know.

JTyson
11-15-2005, 12:15 AM
Ive said it before but cleanup2.php also has the same delete statement in it that needs to be modified.

caliman
11-15-2005, 12:16 AM
Ive said it before but cleanup2.php also has the same delete statement in it that needs to be modified.

So is it working for you JTyson?

Paul M
11-15-2005, 12:41 AM
Thanks, There was a typo on my part. If you have the final spider code input let me know and I will add it and your credits to the install.

Zip file is updated.This bit
intval((TIMENOW - 86400)) only needs one bracket each side. :)

caliman
11-15-2005, 01:26 AM
So does this thing work for you Paul? Anybody? Seems like the behavior I described earlier is still happening for a few people here.

tcs
11-15-2005, 01:36 AM
This bit
intval((TIMENOW - 86400)) only needs one bracket each side. :)


Thanks, Fixed it in the zip file. Also added to change cleanup2.php. I can concede that this might need to be changed even though it works fine on my site without this additional change.

For those that don't wish to download the zip again this is the code. If you don't wish to change it the (( is fine too.


$vbulletin->db->query_write("
DELETE FROM " . TABLE_PREFIX . "session
WHERE lastactivity < " . intval(TIMENOW - 86400) . "
### Delete stale sessions ###


Chuck

amykhar
11-15-2005, 02:30 AM
I'm not so sure about the quality of the data. Right now, it's saying I've had 59 members on in the last 3 hours - but my Total Members that have visited the site today says only 46 have logged in today.

Amy

tcs
11-15-2005, 10:33 AM
I'm not so sure about the quality of the data. Right now, it's saying I've had 59 members on in the last 3 hours - but my Total Members that have visited the site today says only 46 have logged in today.

Amy

No it is doing what it is meant to do. It is a Hit counter for a day. Counts all the visitors to your site. If you visit your site twice then that is 2 registered members hit's.

Now it has a error, it didn't clean out at midnight last night and I need to figure out why, I am pulling the hack till I get it back to the way I intended it to work.

COBRAws
11-15-2005, 03:56 PM
With this code running, I am having the same error others are reporting. The results are for one hour, even though it's been running for several. I am at work right now and won't be able to analyze the code till later. If I figure out what's amiss, I'll let y'all know.

same here, more than 36hrs running and only see the last hour stats.

Will wait till tcs works on the redo :D

lexx27
11-16-2005, 12:17 AM
Yep, waiting for the... redo

COBRAws
11-16-2005, 01:36 AM
I received the update email but the attachment is the same :S

tcs
11-16-2005, 01:36 AM
There is nothing wrong with the code. The only thing that can cause it to not count up is a script that would be cleaning out you sessions table.

Cleanup.php does this every hour that is why we change the code.

cleanup2.php does empty the sessions table after midnight. We want this to happen.

If you want me to look at your cleanup.php you can email it to me.

COBRAws
11-27-2005, 11:03 PM
Sorry for the delay. It works now, my mistake. :(

OneShot
12-07-2005, 11:53 PM
TCS could you look at my cleanup.php because I have followed the changes in this thread and it still counts to a max of two hours before resetting again.

Cheers
OS

ShawnV
12-18-2005, 02:54 AM
The “MOD” installed fine, however it seems to be acting rather strange, I edited the file per the instructions, It reads 8 users in 1 hour, log out and view the site as a guest it reads 3 in the last 1 hour, log in as another users and its 6, any idea on why it wouldn’t be the same number for everyone?

groberthall
12-18-2005, 06:36 AM
I am also getting problems with this. It did start counting the hours once it passed midnight, and it got up to 'last 13 hours' at which time I hit the page refresh ( for other reasons ) and it reset to 1 hour again.

any ideas ?

ShawnV
12-18-2005, 01:00 PM
Yes, mine is also doing that, Total users that have visited today: 3, its showing 2 users now in the last 2 hours (shrug)

groberthall
12-19-2005, 05:37 AM
I may have solved it. I am up to 11 hours and refreshing the page does not reset the counter.

All I did was make exactly the same change to cleanup2 as it says to do to cleanup.php ( as suggested in earllier posts )

ShawnV
12-19-2005, 11:20 AM
I may have solved it. I am up to 11 hours and refreshing the page does not reset the counter.

All I did was make exactly the same change to cleanup2 as it says to do to cleanup.php ( as suggested in earllier posts )


Yes, but did it reset at midnight or did it keep on counting into the next day?

groberthall
12-20-2005, 06:56 AM
No :) the damn thing reset at server midnight. I am ready to give up on this.

ShawnV
12-21-2005, 03:24 PM
No :) the damn thing reset at server midnight. I am ready to give up on this.

Same,

Uninstalling this modification :(

groberthall
12-22-2005, 12:52 PM
Well, I guess it is doing what the author actually said it would do. It counts to 24 hours then resets itself.....

But what we actually want ( :) ) is something that keeps on counting by dropping hour 1 when it reaches hour 25. ( or better still, lets us set how long it will count for ( last 24 hours, last week, last month etc )

Any ideas ?

LoOnEyToOnZ
12-29-2005, 01:52 AM
Well, I guess it is doing what the author actually said it would do. It counts to 24 hours then resets itself.....

But what we actually want ( :) ) is something that keeps on counting by dropping hour 1 when it reaches hour 25. ( or better still, lets us set how long it will count for ( last 24 hours, last week, last month etc )

Any ideas ?

Anyway to put this on vba portal also ?

yayvb
12-29-2005, 04:30 PM
Crap, by the name of the hack I thought it was going to drop off the 1st hour once it gets to the 25th hour, thus constantly showing a large number of users at all times. If it resets at midnight it will go back from the beginning and will not show how many people were in the last 24 hours.

Also, I am having the same problem where it shows 1 hours worth of people.
*EDIT - I changed the cleanup2.php file, I'll let you know if it doesn't help*

tcs
01-30-2006, 11:52 AM
Crap, by the name of the hack I thought it was going to drop off the 1st hour once it gets to the 25th hour, thus constantly showing a large number of users at all times. If it resets at midnight it will go back from the beginning and will not show how many people were in the last 24 hours.

Also, I am having the same problem where it shows 1 hours worth of people.
*EDIT - I changed the cleanup2.php file, I'll let you know if it doesn't help*

It's an easy fix to do a 24hr from now hack instead of the Last 24hr. I will test now and get back with you on this.

I will also include vBadvanced CMPS mudule with it.

3mr3
02-23-2006, 04:58 PM
very nice, thank you