View Full Version : [release vB2.0]couter in vB page
a. open vb2/global.php
find:
// ###################### Start init #######################
Immediately ABOVE it put any PHP counter, i using this:
// ipcounter hack by CX
// config
// create these two files count.txt and ip.txt, chmod them to 777
$count_file = "count.txt";
$ip_file = "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
b. edit the template footer
find in last:
</smallfont>
</p>
Immediately ABOVE it put:
<br><br>
page views: today = $detail[1], total = $detail[2]. variant IP visitors: today = $detail[3], total = $detail[4].
Done!
First-Man
05-25-2001, 04:36 PM
Where can i see an Demo?
thx
bbqfan
05-25-2001, 06:41 PM
see the demo.jpg:
Degen
05-25-2001, 06:55 PM
It works on my board, but I get this at the top of my page :
Warning: file("../addons/count.txt") - No such file or directory in /home/gaminghq/public_html/forums/global.php on line 69
Warning: file("../addons/ip.txt") - No such file or directory in /home/gaminghq/public_html/forums/global.php on line 70
Warning: fopen("../addons/ip.txt","w") - No such file or directory in /home/gaminghq/public_html/forums/global.php on line 101
Warning: Supplied argument is not a valid File-Handle resource in /home/gaminghq/public_html/forums/global.php on line 102
Warning: Supplied argument is not a valid File-Handle resource in /home/gaminghq/public_html/forums/global.php on line 103
Warning: Supplied argument is not a valid File-Handle resource in /home/gaminghq/public_html/forums/global.php on line 104
Warning: fopen("../addons/count.txt","w") - No such file or directory in /home/gaminghq/public_html/forums/global.php on line 108
Warning: Supplied argument is not a valid File-Handle resource in /home/gaminghq/public_html/forums/global.php on line 109
Warning: Supplied argument is not a valid File-Handle resource in /home/gaminghq/public_html/forums/global.php on line 110
Warning: Supplied argument is not a valid File-Handle resource in /home/gaminghq/public_html/forums/global.php on line 111
Not sure what to make of this :(
bbqfan
05-25-2001, 07:41 PM
see this?
$cxip_count_file = "../addons/count.txt"; // check the path
$cxip_file = "../addons/ip.txt"; // check the path
check the path first plx...:(
i set the path of count.txt and ip.txt to "../addons/", if you like, you can change it to anything else...
or like this:
chage those two lines to:
$cxip_count_file = "count.txt"; // check the path
$cxip_file = "ip.txt"; // check the path
it will be ok!
bokhalifa
05-25-2001, 07:42 PM
good werk;)
Blue2000
05-26-2001, 12:16 PM
i made a live counter ages ago
its posted here somwhere
i can repost it if people what it
maverick1236
05-26-2001, 12:56 PM
Id like to see it :)
TimberLand
05-26-2001, 04:11 PM
Anyway to make this an option only the admin can see.
ztsky
05-26-2001, 05:22 PM
Good hack.
I'll try it on my vb page.
ccxx
Degen
05-26-2001, 07:18 PM
BBQFan,
I made the changes, but am still getting the same errors. :(
You have to create two files, called count.txt and ip.txt and chmod them to 777.
Hm, i think there is something wrong.
It always displays this: (it is installed since two days)
vb test received page views: today = 1, total = 22. variant IP visitors: today = 1, total = 22.
today = 1 ? What does this mean? I know that there were more than one person on my test board, it should display today = 2 or so.
Suggestions on this?
Lesane
05-29-2001, 07:56 AM
Originally posted by h4p3
Hm, i think there is something wrong.
It always displays this: (it is installed since two days)
vb test received page views: today = 1, total = 22. variant IP visitors: today = 1, total = 22.
today = 1 ? What does this mean? I know that there were more than one person on my test board, it should display today = 2 or so.
Suggestions on this?
same problem here
Santa
05-29-2001, 08:15 AM
same prob here too :(
Santa
BradC
05-29-2001, 01:27 PM
yah I am having the same problem.... but I am going to use another counter and just intergrate it tonight :)
or tweak this one to work...
bbqfan
05-30-2001, 02:37 AM
Originally posted by h4p3
Hm, i think there is something wrong.
It always displays this: (it is installed since two days)
vb test received page views: today = 1, total = 22. variant IP visitors: today = 1, total = 22.
today = 1 ? What does this mean? I know that there were more than one person on my test board, it should display today = 2 or so.
Suggestions on this?
Hi guys!
would you plx tell me where your test boards are? maybe i can find out any mistakes in this mini hack...:(
but it works ok for me...
http://vbgatetest.51.net/vgate/vb
bbqfan
05-30-2001, 02:55 AM
i have found some servers set this::(
$ENV{REMOTE_ADDR} = 127.0.0.1
so every day the number of variant IP visitors is very ONE... we may try to change the counter code:
$cxip_userip = getenv('REMOTE_ADDR');
to this new line:
$cxip_userip = getenv('HTTP_X_FORWARDED_FOR');
if you test vB on your local PC(like me), the visitors' IP always be 127.0.0.1. of course "variant IP visitors: today = 1,"...
Santa
05-30-2001, 06:31 AM
still wont work.
I get today=1
total=1809
Santa
bbqfan
05-30-2001, 02:47 PM
Originally posted by Santa
still wont work.
I get today=1
total=1809
Santa
which "today"? views or IP?
i think this hack code just simple or i should double check it...
Nope, both.
I tested it on my local Server (Gateway) and on my dedicated Server for my website -> same effect.
bbqfan
05-30-2001, 03:45 PM
my GOD... i m very very sorry for my mistakes...
:(
the right codes have been put in the first post of this thread...
this time every thing would be ok...
Santa
05-30-2001, 04:13 PM
Yeahhh now it works :)
bbqfan
05-30-2001, 04:20 PM
Originally posted by Santa
Yeahhh now it works :)
thank you! i can set my heart at rest now...:):D
Santa
05-30-2001, 04:54 PM
no mate. make more of this hacks :D
bbqfan
05-31-2001, 07:16 PM
sorry again!:(
another bug: these 2 variables $t and $day are collided with vB...
so it will bring on some unpredictable results...:(
the right codes have been put in the first post of this thread... i think so :)
BradC
06-02-2001, 01:25 PM
Great... it works just fine now.. but
Where else can we put the counter code so that it does not count everything... like when you click on a forum.. and read a post.. or go to another page that is including the global.php file.. it counts as a daily visit.. heh :)
ThomasP
06-02-2001, 07:22 PM
Hi there,
works perfect,
thanks!
-Tom
bbqfan
06-02-2001, 11:37 PM
Originally posted by BradC
Great... it works just fine now.. but
Where else can we put the counter code so that it does not count everything... like when you click on a forum.. and read a post.. or go to another page that is including the global.php file.. it counts as a daily visit.. heh :)
mmmh, i think it is easy too...
maybe you can put the display code like this:
this page views: today = $detail[1], total = $detail[2]. variant IP visitors: today = $detail[3], total = $detail[4].
in any Templates you want, instead of the Templates FOOTER, or you can just display one or more of $detail[1]~~[4].
but, you have to create some new count.txt and ip.txt.:(
ThomasP:
Hi there,
works perfect,
thanks!
-Tom
you are welcome:)
ThomasP
08-02-2001, 08:22 PM
Sorry to bring this up again, but it works perfect in 2.0.3 and I reeeaaally love it :D
cu,
-Tom
Robert Basil
08-16-2001, 01:07 AM
I just put the hack in my forums and also placed it throughout my website. Works great, thanks!
eva2000
08-16-2001, 06:03 PM
just tried this hack and it was doing fine for a few minutes and then reset itself again to zero?
Harry
08-16-2001, 07:32 PM
I get exact the same error at different times.... now 879 hits and a few minutes later it starts over at 0
Dakota
08-17-2001, 08:18 AM
Its working fine for me, I just installed it. It may reset, but you never know. :p
Pie'oh'pah
08-18-2001, 07:13 AM
Well, just installed it, too :D
nicely done mate. any chance of making this part of the database?
-Alex
I have installed bbqfan's hack and it works great!! I wanted to keep a running history
of my page views and unique IP's so I made the following hack and attached a
picture of what it looks like. There may be a better way to do this...but this is
as simple a hack as I could create!
NOTE: I could only figure out how to get this to work for daily stats. Weekly/Monthly
don't calculate correctly. If anyone knows what to add/change in the query
to get Weekly/Monthly to show correctly, please post the changes here!
Here's what you need to do:
First create a table called 'ip_views' in your vbulletin database, and add the
following fields: 'date' as INT(10), 'views' as INT(6), 'uip' as INT(6)
Note: You can run the following query in phpMyAdmin to create the table:
CREATE TABLE ip_views (
date int(10) NOT NULL,
views int(6) NOT NULL,
uip int(6) NOT NULL
)
================================================== ============
** In bbqfan's hack in global.php
Find:
} else {
$detail[0]=$count_day;
CHANGE it to:
} else {
$DB_site->query("INSERT INTO ip_views (date,views,uip) VALUES ('$count_t',$detail[1],$detail[3])");
$detail[0]=$count_day;
Done with global.php!
** Open admin/stats.php
Find:
echo "<option value=\"thread\">Threads</option>\n";
Below it add:
echo "<option value=\"views\">Page Views</option>\n";
echo "<option value=\"uips\">Unique IP's</option>\n";
Find:
} elseif ($type == "user") {
$table = "user";
$field = "joindate";
}
CHANGE it to:
} elseif ($type == "user") {
$table = "user";
$field = "joindate";
} elseif ($type == "views") {
$table = "ip_views";
$field = "date";
$field2 = "views";
} elseif ($type == "uips") {
$table = "ip_views";
$field = "date";
$field2 = "uip";
}
Find:
$stats = $DB_site->query("SELECT COUNT(*), DATE_FORMAT(FROM_UNIXTIME($field),'$sqlformat') AS timeframe, MAX($field) FROM $table WHERE $field > '$from' AND $field < '$to' GROUP BY timeframe ORDER BY $field $sort");
CHANGE it to:
if (($type == "thread") || ($type == "post") || ($type == "user")) {
$stats = $DB_site->query("SELECT COUNT(*), DATE_FORMAT(FROM_UNIXTIME($field),'$sqlformat') AS timeframe, MAX($field) FROM $table WHERE $field > '$from' AND $field < '$to' GROUP BY timeframe ORDER BY $field $sort");
} elseif (($type == "views") || ($type == "uips")) {
$stats = $DB_site->query("SELECT $field2, DATE_FORMAT(FROM_UNIXTIME($field),'$sqlformat') AS timeframe, MAX($field) FROM $table WHERE $field > '$from' AND $field < '$to' GROUP BY timeframe ORDER BY $field $sort");
}
Done with admin/stats.php!
This works on vBulletin 2.0.1...any other 2.x versions should work, but I
can't verify. Hopefully someone will know how to make the weekly and
monthly stats add up the views/ip's correctly for the week/month!
AJ
Strange...the picture didn't attach in the above post. Here it is:
Robert Basil
08-19-2001, 09:04 PM
This hack was working great for almost a full 24hrs and then it started resetting itself at random times back to zero (Both the visitor stats and the page view stats) So I removed it from my site.
eva2000
08-19-2001, 09:07 PM
Originally posted by Sportbikeworld
This hack was working great for almost a full 24hrs and then it started resetting itself at random times back to zero (Both the visitor stats and the page view stats) So I removed it from my site. yup join the club :(
Dakota
08-21-2001, 04:22 AM
After afew hours I was at about 1500 page views, then I checked back the next morning and it was at like 250. Reset is occuring with me too.
eva2000
08-28-2001, 03:55 AM
try this mysql counter http://vbulletin.com/forum/showthread.php?s=&threadid=26527 doesn't reset at all :D
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.