PDA

View Full Version : A decent, free, hit counter?


Aaron
01-22-2003, 08:43 AM
Can anyone recommend a decent, free, hit counter. Basically all I want is something that will count unique visitors and give me a few stats in an easy to understand format. Is that too much to ask?

Steven
01-22-2003, 11:46 AM
Hi Aaron,
Check out http://www.sitemeter.com/

-Steven

harmonic
01-22-2003, 01:45 PM
I would check out http://www.hotscripts.com/ and look for one thats free, cause you won't be getting ads if you install the script yourself.

Aaron
01-22-2003, 02:21 PM
Thanks for the input, guys.

I'm using sitemeter now on the recommendation of another friend.

I'm also looking at all the options at hostscripts.com - there is so much there, though, that I'm on overload.

harmonic
01-22-2003, 02:51 PM
http://www.hotscripts.com/PHP/Scripts_and_Programs/Counters/Hosting_Tools/

Aaron
01-23-2003, 01:44 PM
I've tried a couple of the php counter/stats scripts and I have a question. The ones I tried looked promising but when I added the include <? $id="1"; $url="http://www.aaronjen.org/counter/count.php"; include("$url"); ?> it didn't do anything. I'm pretty sure I'm doing something wrong but have no idea what it might be. Why do php programmers just assume everyone who might want to use their script is going to know what they're doing? (I'm the the programming gurus here aren't like that.)

Oh well, back to the drawing board. :eek:

dnxnet
01-27-2003, 02:52 PM
yep because php's: include() function is worked on the filesystem and not HTTP.

$url = "/home/username/public_html/folder/count.php"

That will do it for you.

But heres a little script for all to use if you want.

-------------------------------------------------------------------------------

Create database and place this dump inside it:

#
# Table structure for table `counter`
#

CREATE TABLE `counter` (
`counter` text NOT NULL
) TYPE=MyISAM;

#
# Dumping data for table `counter`
#

INSERT INTO `counter` (`counter`) VALUES ('0');
# --------------------------------------------------------

#
# Table structure for table `daily_hits`
#

CREATE TABLE `daily_hits` (
`date` text NOT NULL,
`ip` text NOT NULL
) TYPE=MyISAM;

#
# Dumping data for table `daily_hits`
#

#
# Table structure for table `usersonline`
#

CREATE TABLE `usersonline` (
`timestamp` int(15) NOT NULL default '0',
`ip` varchar(40) NOT NULL default '',
`file` varchar(100) NOT NULL default '',
PRIMARY KEY (`timestamp`),
KEY `ip` (`ip`),
KEY `file` (`file`)
) TYPE=MyISAM;

#
# Dumping data for table `usersonline`
#

INSERT INTO `usersonline` (`timestamp`, `ip`, `file`) VALUES (1035423939, '127.0.0.1', 'Mailing List');

------------------------------------------------------------------------------
Next you have to make the background script which will run this baby!

--------------------------------------------------------------------------------
Create a file called: stats.php , and place this inside it.

<?php
@mysql_connect( "localhost","username","password" );
@mysql_select_db( "database_name" );
$date = date( "j/m/Y" );
$daily1 = "INSERT INTO daily_hits
(date, ip)
VALUES
('$date', '$REMOTE_ADDR') ";

$re = mysql_query( $daily1 );
$delete = "DELETE FROM daily_hits
WHERE date <> '$date' ";

$del = mysql_query( $delete );
$main_counter = mysql_query( "SELECT counter
FROM counter " );

$gy = mysql_fetch_array( $main_counter );
$new_count = $gy['counter'] + 1;
$up = mysql_query( "UPDATE counter
SET counter='$new_count'" );

$sql = mysql_query( "SELECT *
FROM users" );

$users = mysql_num_rows( $sql );

$sql = mysql_query( "SELECT *
FROM daily_hits" );

$daily = mysql_num_rows( $sql );

$sql = mysql_query("select counter from counter");
$count = mysql_fetch_array($sql);

$timeoutseconds = 30;
$timestamp = time();
$timeout = $timestamp-$timeoutseconds;
$insert = mysql_query("INSERT INTO usersonline VALUES ('$timestamp','$REMOTE_ADDR','$page')");
if(!($insert)) {
print "Useronline Insert Failed > ";
}
$delete = mysql_query("DELETE FROM usersonline WHERE timestamp<$timeout");
if(!($delete)) {
print "Useronline Delete Failed > ";
}
$result = mysql_query("SELECT DISTINCT ip FROM usersonline");
if(!($result)) {
print "Useronline Select Error > ";
}
$user = mysql_num_rows($result);
if($user == '1') {
$online = "$user";
} else {
$online = "$user";
}

?>

-------------------------------------------------------------------------------

Now thats the hard work done, all you have to do now is call that script onto your page:

On the page you want the counter, place this before anything else on the page (Before <HTML>):

<?php
include( "/path/to/stats.php" );
?>

Now, where you want the users online and site hits to be placed on your page just put this code:

<b><?php echo $online ?></b> user online. With: <b><?php echo $daily ?></b> Pages views today, and a total of: <b><?php echo $count[counter] ?></b> views.

---------------------------------------------------------------------------------

Hope everyone can enjoy the power of PHP. Should make this sticky, its a pretty common request. :)

merockyw
01-04-2009, 05:48 AM
I seen dnxnets post for a hit counter. I would really like to use this on my web page. I don't understand (Create database and place this dump inside it)
Do I make this with notepad? I have made pages from notepad but saved them as htm or text files. Could someone please give me a few more directions? Thanks PS I need a hit counters for dummys explanation. Thanks