View Full Version : PHP Mini Hit counter for vB
Thomas P
09-30-2002, 12:50 PM
Hello,
I'm looking for a simple hit counter for my forumhome page.
Currently I use a snippet which breaks every x hours :(
It is a file based counter I inserted into the phpinclude template and I echo the figures with variables.
What it does is it shows me daily hits, which reset every 24h and total hits with all hits since the beginning.
Does anyone has an alternative to my counter which doesn't break?
Many, many thanks,
-Tom
g-force2k2
09-30-2002, 04:42 PM
what do you mean doesn't break?
If im correct in understanding what you mean... you can use mysql to store the data to get the effect you're looking for...
CREATE TABLE hits (
hitid int(10) unsigned NOT NULL DEFAULT '0',
hitname varchar(30) NOT NULL,
hits int(10) NOT NULL DEFAULT '0',
PRIMARY KEY(hitid)
)
INSERT INTO hits VALUES ('1', 'index', '0')
run those two queries and then open index.php
find:
eval("dooutput(\"".gettemplate('forumhome')."\");");
above it add:
$DB_site->query("UPDATE hits SET hits=hits+1 WHERE hitname='index'");
$hits = $DB_site->query_first("SELECT hits FROM hits WHERE hitname='index'");
$hits = $hits['hits'];
then in your forumhome tempate place $hits whereever you want the hits to show... i doubt this is the most effective way but it should do the trick ;)
regards...
g-force2k2
Thomas P
10-01-2002, 08:58 AM
Thanks g-force2k2,
I'll try it :)
what do you mean doesn't break?
I don't know why, but my textcounter "breaks" sometimes, i.e. resets all numbers and starts to count from 0 :(
Thank you very much, I think what you posted here is that what I need, but I need one more thing ;)
Is it difficult to add a figure which shows the number of daily users (e.g. $hitsdaily)? :)
Thanks,
-Tom
Thomas P
10-02-2002, 06:51 AM
Please stay with me :)
Just this one little addition would make my users happy :)
Thank you,
-Tom
NTLDR
10-02-2002, 10:32 AM
Why not install vBstats? This has many statistics for you, like hits per day, total, thread views total, users online in a day, posts in the last 24 hrs etc...
Thomas P
10-02-2002, 12:11 PM
Yeah, I know...
I just need to replace my old counter, which'll exist next to vBstats.
http://www.mcseboard.de/ - I have to figures, down to the right, dark shaded is the number of Hits sinc 05/2001 (would be $hits in g-force2k2 hack)
and the number of "guest hits", which is the number of $hits in the last 24h
Thanks anyway, :)
-Tom
Thomas P
10-09-2002, 06:34 AM
Here's the file based counter I use now, which breaks ~3 times a day:
// ipcounter hack by CX
// config
// create these two files count.txt and ip.txt, chmod them to 777
$count_file = "counter.txt";
$ip_file = "counter_ip.txt";
$userip = getenv('REMOTE_ADDR'); // in some fixed IP server, change this line to $userip = getenv('HTTP_X_FORWARDED_FOR');
$count_temp=file($count_file);
$ip_temp=file($ip_file);
$detail=explode("|",$count_temp[0]);
$count_t=getdate(time());
$count_day=$count_t['mday'];
if ($detail[0]==$count_day) {
$detail[1]++;
$detail[2]++;
$count=count($ip_temp);
$check=1;
for ($i=0; $i<$count; $i++) {
$ip_list=str_replace("\r","",str_replace("\n","",$ip_temp[$i]));
if ($ip_list==$userip) $check=0;
}
if ($check==1) {
$detail[3]++;
$detail[4]++;
$fp=fopen($ip_file,"a");
flock($fp,3);
fputs($fp,$userip."\n");
fclose($fp);
}
}
else {
$detail[0]=$count_day;
$detail[1]=1;
$detail[3]=1;
$detail[2]++;
$detail[4]++;
$fp=fopen($ip_file,"w");
flock($fp,3);
fputs($fp,$userip."\n");
fclose($fp);
}
$new=implode("|",$detail);
$fp=fopen($count_file,"w");
flock($fp,3);
fputs($fp,$new);
fclose($fp);
// end ipcounter hack
$i = $HTTP_GET_VARS['i'];
Thanks,
-Tom
Thomas P
10-15-2002, 09:29 AM
Okay, I took a ready made script and integrated it into vB
http://www.needscripts.com/Resource/1447.html
Sad how few support someone can get over here with an easy thing like a counter. I'm not trying to be sarcastic or anything, it's just a fact and I'm curious...
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.