Jump to content

Recommend a PHP Site Tracking Script


bpops

Recommended Posts

It'd be very simple to write your own.

 

Either flat file :

 

php5

<?php
$ip = $_SERVER['REMOTE_ADDR'];

$filename = "hits.txt";
file_put_contents($filename, $ip, FILE_APPEND);

$file = file("hits.txt");
$num = count($file);

echo "This page has been viewed $num times";
?>

 

php4

$ip = $_SERVER['REMOTE_ADDR'];
$filename = "hits.txt";

$fp = fopen($filename);

fwrite($fp, $ip);

fclose($fp);

$file = file($filename);
$num = count($file);

echo "This page has been viewed $num times";

 

or with a database:

assuming a table called hits with field IP(unique and primary key)

 

$ip=$_SERVER['REMOTE_ADDR'];

$sql = "REPLACE INTO `hits` (`IP`) VALUES ('$ip')";
$result = mysql_query($sql) or die("Error in sql: ".mysql_error());

$sql_a = "SELECT Count(ip) FROM `hits`";
$result_a = mysql_query($sql_a) or die("Error in sql_a: ".mysql_error());

$row  = mysql_fetch_array($result_a);
$num = $row['Count(ip)'];

echo "this page has been viewed $num times";

 

Untested but should work. Only took maybe 3 minutes to write on the fly so just mess around with those. Unless you want an image based one..

 

Hope that helps

Sam

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.