PDA

View Full Version : page - hit counter in mysql


eva2000
27 Aug 2001, 01:28
Who would ever think me releasing something :D

Being a newbie at php/mysql programming i had help from tutorials all over the place and from freakysid from SPF forums :)

1. MySQL based counter

You need:
1. phpmyadmin - http://sourceforge.net/projects/phpmyadmin/ -phpmyadmin install and use guide (http://vbulletin.com/forum/showthread.php?s=&threadid=18558) to add a table named mycounter to your existing vB database.

you need to select you vb database name listed in the left of phpmyadmin and run the following queries once in phpmyadmin

CREATE TABLE mycounter (count INT(11) UNSIGNED NOT NULL);
INSERT INTO mycounter SET count = 0;

i.e. if my vb database is named usertest you should enter like this the screen cap below or here (http://vbulletin.com/forum/attachment.php?s=&postid=161469).

2. need to edit your phpinclude template and add the following in:

$result = mysql_query("SELECT count FROM mycounter");
$mycounter = mysql_result($result, 0) + 1;
$result = mysql_query("UPDATE mycounter SET count = count + 1");

save changes

3. then place $mycounter in your footer template

Ruth
28 Aug 2001, 06:08
looks nice,

is there a demo?

and how does it work? based on logins? or specified ip adress?

eva2000
28 Aug 2001, 06:10
based a raw pageview hits... you can see it working on my vB at the bottom of each page http://animeboards.com/

i'm still a newbie with php but working on it :D

merk
28 Aug 2001, 06:24
A sugestion eva2k...

Im after a counter script myself, which yours is great for, but i need one to also record the HTTP_REFFERER, and useragent, and i dont really want to us webtrends :/

I could try to add these features for you if you want me to? ;)

eva2000
28 Aug 2001, 06:37
Originally posted by merk
A sugestion eva2k...

Im after a counter script myself, which yours is great for, but i need one to also record the HTTP_REFFERER, and useragent, and i dont really want to us webtrends :/

I could try to add these features for you if you want me to? ;) sure why not.. i'm planning to do this too but i have to learn how to do it first (it's only been 48 hrs since i started learning php :o )

merk
28 Aug 2001, 06:51
Ive done php for some time, but never have gotten around do doing anything of any importance :/

FWC
28 Aug 2001, 07:33
Who would ever think me releasing something

That's a nice hack. I installed it.

_
28 Aug 2001, 17:25
lol eva

the counter on AB is just like a stopwatch almost, it goes up like 2 every second (3 if you include me =)

Bane
28 Aug 2001, 17:34
Originally posted by merk
A sugestion eva2k...

Im after a counter script myself, which yours is great for, but i need one to also record the HTTP_REFFERER, and useragent, and i dont really want to us webtrends :/

I could try to add these features for you if you want me to? ;)

In case anyone is interested, I am putting together something like this. You can view an example of the output at:

http://www.talkloud.net/forums/vbstats.php

As far as the referrer check

http://www.talkloud.net/forums/vbstats.php?action=incoming

dxb
28 Aug 2001, 18:59
hi there eva

you did it at last :)

thanks for the counter

and Bane the stats look really great ....yes I'm intersted in and I will be waiting for if

but could you make it so that you can add it to a VB page and a non VB page if it's possible :)

Dakota
28 Aug 2001, 23:49
Bane that looks really good. I hope you release it

merk
29 Aug 2001, 03:32
Geezes, you must have taken your time to make something like that!

I cant ever get the motivation to create something like it :/

MarkB
29 Aug 2001, 08:54
Nice stuff, Eva :) Now to get depressed about how low the page count is :p

merk
29 Aug 2001, 09:06
Lol, good point there :( :(

eva2000
29 Aug 2001, 11:06
really i only want a simple pageview counter to compare against my banner script impressions and my site log files since my figures seem to differ a bit in each

BluSmurf
09 Sep 2001, 10:27
So when is eva gonna come up with the stats same as Bane's? I'll be waiting :D ... I have faith in you! hehehehee

BluSmurf

Bane
09 Sep 2001, 16:35
Mine is coming out very soon :)

chrispadfield
12 Sep 2001, 18:25
eva, wondering if there is a problem here. Have installed this a few weeks ago but just added the line to the bottom. Anyway, every refresh i do the hit counter is going up at least 5 with only 20 odd on the forums. This does not seem very likely to me.

So i was wondering, does avatar.php activate the phpinclude every time it is run?

YourHostSucks
29 Sep 2001, 02:55
Fun little add-on, Thanks ;)

DarkReaper
29 Sep 2001, 04:59
Me wants to see bane's! :)

Its not loading for me....

ezop
29 Sep 2001, 14:10
nice work, works a treat..:)

eva2000
31 Oct 2001, 15:16
nearly forgot about this :o

For the record it's still working on my forums :)


Pageviews since Aug 27, 2001 - 10:00 am (AEST): 2668665

MrLister
31 Oct 2001, 15:34
hehe that's quite a few... i guess it works great.

maverick1236
04 Nov 2001, 01:58
NICELY DONE!!!

Works Perfect!!

Thank You!!

eva2000
04 Nov 2001, 02:00
thanks.. i had help from freakysid too so not all my work :)

SWFans.net
21 Nov 2001, 16:30
I was curious if there was any way to use the figures generated by this hack to come up with page views for the last 24 hours?

Chrysalis
31 Dec 2001, 01:30
the hack worked but it wouldnt accept the following command

CREATE TABLE mycounter (count INT(11) UNSIGNED NOT NULL);

so i used CREATE TABLE mycounter (count INT(11)); instead and the hack works a treat.

Bedhead
31 Dec 2001, 02:00
Great job!

PhotoGenie
02 Feb 2002, 18:56
Great hack.. Only thing I see that should be changed is the placement of it in your page. Someone posted above that they thought avatars might be registering as visits and that his visits were going up 5 times more than they should be. What happens is you put the counter in your footer and then your really just registering clicks and not how many visits to the home page. Your footer shows everywhere so every time a page is loading it is counted as a visit. If you put it in your forumhome template It will only register your main page.

Example:

Welcome to our newest member, <a href="member.php?s=$session[sessionhash]&action=getinfo&userid=$newuserid"><b>$newusername</b></a><br>
There has been <b>$mycounter</b> visits to this page since July 16th, 2001
</smallfont></td>
<td align="right"><smallfont>
The time now is $timenow.<br>


Thanks for the hack I'm using it now. :)

PhotoGenie
03 Feb 2002, 18:40
Still counting clicks after making changes above. I went back and tried a few other things and got it fixed where it is only counting visits to the main page. Here's the changes below.

I removed :

$result = mysql_query("SELECT count FROM mycounter");
$mycounter = mysql_result($result, 0) + 1;
$result = mysql_query("UPDATE mycounter SET count = count + 1");

from my phpinclude template.

Open index.php:

find around line 69

$birthdaybits="";

just above it insert

$result = mysql_query("SELECT count FROM mycounter");
$mycounter = mysql_result($result, 0) + 1;
$result = mysql_query("UPDATE mycounter SET count = count + 1");

and that will fix it to where it only counts the index page.

You can now insert:

$mycounter

Wherever you want your count to appear.

PhotoGenie
04 Feb 2002, 00:17
Here is my installation of eva2000's hit counter hack.. I created a text file in order to save the install for myself.

Lucky
24 Feb 2002, 18:02
Working on 2.2.2, but for some reason it is counting 2 at a time.

Any ideas?

Thank you.

PhotoGenie
25 Feb 2002, 01:34
Originally posted by Lucky
Working on 2.2.2, but for some reason it is counting 2 at a time.

Any ideas?

Thank you.

Read a couple of post above yours:)

Lucky
25 Feb 2002, 06:58
I realize this, but I want to show total page views not just on the forum home page but all.

PhotoGenie
25 Feb 2002, 13:30
Good luck :)

wolfe
02 Mar 2002, 04:01
how do i make it have a , like this


67,482

Jakeman
07 Mar 2002, 10:43
installed, works :)

nuno
11 Mar 2002, 16:56
nice hack george :)
how can we make it to show daily views also?

eva2000
12 Mar 2002, 02:56
Originally posted by wolfe
how do i make it have a , like this


67,482 change what you have in phpincludes to

$result = mysql_query("SELECT count FROM mycounter");
$mycounter = mysql_result($result, 0) + 1;
$mycounter = number_format($mycounter);
$result = mysql_query("UPDATE mycounter SET count = count + 1");

eva2000
12 Mar 2002, 02:58
Originally posted by nuno
nice hack george :)
how can we make it to show daily views also? use bane's vBstats hack or install www.phpee.com ;)

Whome
15 Mar 2002, 14:03
Thank you...installed this one :)

Lucky
16 Mar 2002, 02:23
Thanks for the , eva2000

Thomas P
09 Oct 2002, 15:52
Sorry, have to reactivate that thread...

@George: Does your counter also show the hits per day?

I have the same problem as you once, my file-based counter resets itself 2-3 times a day :( :( (www.mcseboard.de)
http://www.vbulletin.com/forum/showthread.php?s=&threadid=26508

Thanks,
-Tom

P.S.: I'm looking for a replacement of this one:
http://www.vbulletin.org/forum/showthread.php?s=&threadid=18096
I joined the club, it now resets itself, too

Thomas P
15 Oct 2002, 12:47
Okay, switched to yours - working fine :)
Changed it to display daily hits as well as the total hits...
cu,
-Tom

Davey
27 Dec 2002, 16:59
Hey eva2000; this is an awesome hack! JUST what I was looking for.
However, if you could, I'd like to see an IP logging function, where all IP addresses are logged to a PHP/text file in the /admin/ directory.
This would be a wonderful feature, in my opinion, and I hope you can make it possible :).

Dave.

PS: If not, then I might attempt myself. In which case, how do you return an ip/hostname?