Web counter

Tony Hammitt thammitt at kc.rr.com
Mon Apr 23 11:08:26 CDT 2001


Hi Jason,

I don't want to sound rude but why would you want a web counter?
They aren't all that popular anymore due to several constraints
like the fact that quite a bit of traffic is from search engines
and other robots.  It's hard to establish an actual baseline of
the number of human visitors, making the numbers almost meaningless.

But it is fairly simple to implement, provided you use some kind
of server-side scripting language like PHP.  You could just put a
little table in an SQL database and have the scripting language
update the entry whenever the page is viewed, this will of course
increment for the robots, too.

You could create the table like follows (I'm using MySQL):

use mydb;
create table hits (
id int not null auto_increment,
number int,
primary key(id));

insert into hits values (1,0);

You'd want to put in some better value than 0 for the number of hits so
far based on what the actual value is.  Then include something like the
following on your pages:

<?php
$db=mysql_connect ("localhost", "<username>", "<password>");
mysql_select_db ("mydb", $db);

$qr = mysql_query("update hits set number=number+1 where id=1", $db);
$qr = mysql_query("select number from hits where id=1", $db);

list( $number ) = mysql_fetch_row( $qr );
mysql_free_result( $qr );

echo "<br><center>Number of visitors: <b>$number</b></center><br>n";
?>

You could always just save that off to a file and say something like the
following on each page:

<?php require("$DOCUMENT_ROOT/counter");?>

I've tested this setup on a local page and it works fine.  Hope this
helps.  If you have any trouble, let me know.

Regards,

	Tony Hammitt

http://www.exampleprograms.org

J Greene wrote:
> 
> Does anyone have or know of an ultra-simple web counter that I can run on
> my web server? Slackware/Apache
> 
> I tried something called SWC and I couldn't get it to work.
> 
> Any ideas?
> Jason
> 
> =====
> http://www.hailmaryfullofgrace.net
> 
> __________________________________________________
> Do You Yahoo!?
> Yahoo! Auctions - buy the things you want at great prices
> http://auctions.yahoo.com/
> 




More information about the Kclug mailing list