PDA

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


bbqfan
25 May 2001, 17:55
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
25 May 2001, 18:36
Where can i see an Demo?
thx

bbqfan
25 May 2001, 20:41
see the demo.jpg:

Degen
25 May 2001, 20:55
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
25 May 2001, 21:41
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
25 May 2001, 21:42
good werk;)

Blue2000
26 May 2001, 14:16
i made a live counter ages ago

its posted here somwhere

i can repost it if people what it

maverick1236
26 May 2001, 14:56
Id like to see it :)

TimberLand
26 May 2001, 18:11
Anyway to make this an option only the admin can see.

ztsky
26 May 2001, 19:22
Good hack.
I'll try it on my vb page.
ccxx

Degen
26 May 2001, 21:18
BBQFan,

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

h4p3
26 May 2001, 22:17
You have to create two files, called count.txt and ip.txt and chmod them to 777.

h4p3
27 May 2001, 20:41
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
29 May 2001, 09:56
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
29 May 2001, 10:15
same prob here too :(

Santa

BradC
29 May 2001, 15:27
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
30 May 2001, 04:37
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
30 May 2001, 04:55
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
30 May 2001, 08:31
still wont work.

I get today=1
total=1809


Santa

bbqfan
30 May 2001, 16:47
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
30 May 2001, 17:16
Nope, both.

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

bbqfan
30 May 2001, 17:45
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
30 May 2001, 18:13
Yeahhh now it works :)

bbqfan
30 May 2001, 18:20
Originally posted by Santa
Yeahhh now it works :)

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

Santa
30 May 2001, 18:54
no mate. make more of this hacks :D

bbqfan
31 May 2001, 21:16
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
02 Jun 2001, 15:25
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
02 Jun 2001, 21:22
Hi there,

works perfect,
thanks!
-Tom

bbqfan
03 Jun 2001, 01:37
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:)

ThomasP
02 Aug 2001, 22:22
Sorry to bring this up again, but it works perfect in 2.0.3 and I reeeaaally love it :D
cu,
-Tom

Robert Basil
16 Aug 2001, 03:07
I just put the hack in my forums and also placed it throughout my website. Works great, thanks!

eva2000
16 Aug 2001, 20:03
just tried this hack and it was doing fine for a few minutes and then reset itself again to zero?

Harry
16 Aug 2001, 21:32
I get exact the same error at different times.... now 879 hits and a few minutes later it starts over at 0

Dakota
17 Aug 2001, 10:18
Its working fine for me, I just installed it. It may reset, but you never know. :p

Pie'oh'pah
18 Aug 2001, 09:13
Well, just installed it, too :D

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

-Alex

AJR
18 Aug 2001, 12:45
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
18 Aug 2001, 12:53
Strange...the picture didn't attach in the above post. Here it is:

Robert Basil
19 Aug 2001, 23:04
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
19 Aug 2001, 23:07
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
21 Aug 2001, 06:22
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
28 Aug 2001, 05:55
try this mysql counter http://vbulletin.com/forum/showthread.php?s=&threadid=26527 doesn't reset at all :D

nuke
31 Dec 2001, 01:06
for Super Hack.