PHP Scripts

Record views of specific pages

If you need to be able to tell clients how many unique visitors have viewed their pages,
then this is a must.

It could be used in conjunction with recording subsequent referrals to their own website.

your_website/client_folder/index.htm

<?php
session_start();
//find out exactly where we are and trim this back to the client directory name only
eg, your_website/clients/corporate/sweatshop/mexico/nike/
will result in 'nike' as current directory
$path = preg_replace("/^\/|\/$/", "", $_SERVER['PATH_TRANSLATED']);
$path_array = split("/", $path);
array_pop($path_array);
$dr = array_pop($path_array);
include "http://www.your_website/count.php?dr=$dr";
echo "</font>";
?>

<html>
blah blah blah
</html>


count.php

<?php
session_start();
$dir=$_GET['dr'];
//next line can be remarked out
echo "<FONT TYPE = VERDANA, ARIAL, HELVETICA SIZE = 1>$dr</FONT>";
$db = @mysql_connect("host","login","password");
if( ! ($db = @mysql_connect("host","login","password")) ) {
echo "Database Error";
exit;
}

mysql_select_db("database",$db) or die("Log error");
$query="SELECT * FROM table WHERE dir = '$dir'";
$result = mysql_query( $query, $db );
$num_rows = mysql_num_rows($result);
if (empty($num_rows)) {
$q1 = "INSERT INTO table (enters,dir) VALUES ('1','$dir')";
mysql_query($q1);

} else {

if ($result) {
$q2 = "UPDATE table SET enters=(enters+1) WHERE dir='$dir'";
mysql_query($q2);
}
}

mysql_close($db);
session_destroy();

?>

 

Back

Source