PDA

View Full Version : [release vB2.0]couter in vB page



bbqfan
Fri 25th May '01, 1:55pm
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:&nbsp;&nbsp;today = $detail[1],&nbsp;&nbsp;total = $detail[2].&nbsp;&nbsp;variant IP visitors:&nbsp;&nbsp;today = $detail[3],&nbsp;&nbsp;total = $detail[4].


Done!

First-Man
Fri 25th May '01, 2:36pm
Where can i see an Demo?
thx

bbqfan
Fri 25th May '01, 4:41pm
see the demo.jpg:

Degen
Fri 25th May '01, 4:55pm
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
Fri 25th May '01, 5:41pm
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
Fri 25th May '01, 5:42pm
good werk;)

Blue2000
Sat 26th May '01, 10:16am
i made a live counter ages ago

its posted here somwhere

i can repost it if people what it

Maverick1236
Sat 26th May '01, 10:56am
Id like to see it :)

TimberLand
Sat 26th May '01, 2:11pm
Anyway to make this an option only the admin can see.

ztsky
Sat 26th May '01, 3:22pm
Good hack.
I'll try it on my vb page.
ccxx

Degen
Sat 26th May '01, 5:18pm
BBQFan,

I made the changes, but am still getting the same errors. :(

h4p3
Sat 26th May '01, 6:17pm
You have to create two files, called count.txt and ip.txt and chmod them to 777.

h4p3
Sun 27th May '01, 4:41pm
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
Tue 29th May '01, 5:56am
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
Tue 29th May '01, 6:15am
same prob here too :(

Santa

BradC
Tue 29th May '01, 11:27am
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
Wed 30th May '01, 12:37am
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
Wed 30th May '01, 12:55am
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
Wed 30th May '01, 4:31am
still wont work.

I get today=1
total=1809


Santa

bbqfan
Wed 30th May '01, 12:47pm
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...

h4p3
Wed 30th May '01, 1:16pm
Nope, both.

I tested it on my local Server (Gateway) and on my dedicated Server for my website -> same effect.

bbqfan
Wed 30th May '01, 1:45pm
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
Wed 30th May '01, 2:13pm
Yeahhh now it works :)

bbqfan
Wed 30th May '01, 2:20pm
Originally posted by Santa
Yeahhh now it works :)

thank you! i can set my heart at rest now...:):D

Santa
Wed 30th May '01, 2:54pm
no mate. make more of this hacks :D

bbqfan
Thu 31st May '01, 5:16pm
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
Sat 2nd Jun '01, 11:25am
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 :)

Thomas P
Sat 2nd Jun '01, 5:22pm
Hi there,

works perfect,
thanks!
-Tom

bbqfan
Sat 2nd Jun '01, 9:37pm
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:&nbsp;&nbsp;today = $detail[1],&nbsp;&nbsp;total = $detail[2].&nbsp;&nbsp;variant IP visitors:&nbsp;&nbsp;today = $detail[3],&nbsp;&nbsp;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:)

Thomas P
Thu 2nd Aug '01, 6:22pm
Sorry to bring this up again, but it works perfect in 2.0.3 and I reeeaaally love it :D
cu,
-Tom

Robert Basil
Wed 15th Aug '01, 11:07pm
I just put the hack in my forums and also placed it throughout my website. Works great, thanks!

eva2000
Thu 16th Aug '01, 4:03pm
just tried this hack and it was doing fine for a few minutes and then reset itself again to zero?

Harry
Thu 16th Aug '01, 5:32pm
I get exact the same error at different times.... now 879 hits and a few minutes later it starts over at 0

Dakota
Fri 17th Aug '01, 6:18am
Its working fine for me, I just installed it. It may reset, but you never know. :p

Pie'oh'pah
Sat 18th Aug '01, 5:13am
Well, just installed it, too :D

nicely done mate. any chance of making this part of the database?

-Alex

AJR
Sat 18th Aug '01, 8:45am
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

AJR
Sat 18th Aug '01, 8:53am
Strange...the picture didn't attach in the above post. Here it is:

Robert Basil
Sun 19th Aug '01, 7:04pm
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
Sun 19th Aug '01, 7:07pm
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
Tue 21st Aug '01, 2:22am
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
Tue 28th Aug '01, 1:55am
try this mysql counter http://vbulletin.com/forum/showthread.php?s=&threadid=26527 doesn't reset at all :D