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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.