Thursday, February 3, 2011

LogIt v1.0

Even if you have a free site or blog like mine, you still advertise it don't you?
The cheapest and easiest way to advertise your site is by asking others to post a banner of your site on theirs and adding a link back to your site or simply a text link on their site
e.g.- <a href="www.mysite.com"><img sre="mybanner.jpg"></a>
Although easy it has one big problem, how would you know how many users visited your site, from which site and which pages were visited the most?
You might have a visitor counter on your site, so do I. But that also won't give you all the details, so here is a script that not only records the date of the visit, but also the user's IP address, from which site they came and which page they visited.
click.php
<?php
// LogIt v1.0
// Script Written By Tanmay Das
// Script © Copyright Design Inline.com

// Opening Databse file
$dbase = 'dbase.txt';
$data = file($dbase);
// Creating array
$array = explode("||", $data[0]);
$today = $array[0]; // Today's date
$ipad = $array[1]; // IP of the user
$reff = $array[2]; // Site from the user came
$frurl = $array[3]; // Page the user wished to go
$today = date("l, F j, Y, g:i a");
$ipad = getenv("REMOTE_ADDR");
$reff = getenv("HTTP_REFERER");
$default0 = home;
$frurl = isset($_GET['url']) ? $_GET['url'] : $default0;
if($frurl != 'home')
{
$insertdata = $today."||".$ipad."||".$reff."||".$frurl."\n";
// Writing data to file
$fp = fopen($dbase,"a");
fputs($fp,$insertdata);
fclose($fp);
header("Location: ".$frurl); // Redirecting user to specified page
}
else
{
$userinfo = file('dbase.txt'); // Opening Database file
// Creating Table
echo '<table border = "1">';
echo '<tr><td>Date</td><td>IP Address</td><td>Referrer Address</td><td>Forwaded URL</td></tr>';
foreach($userinfo as $key => $val)
{
//explode that data into a new array:
$data[$key] = explode("||", $val);
}
for($k = 0; $k < sizeof($userinfo); $k++)
{
echo '<tr><td>'.$data[$k][0].'</td><td>'.$data[$k][1].'</td>';
echo '<td><a href="'.$data[$k][2].'">'.$data[$k][2].'</a></td><td><a href="'.$data[$k][3].'">'.$data[$k][3].'</a></td></tr>';
}
echo '</table>';
}
?>

Just save it as say click.php upload it on your server along with a blank text file named dbase.txt.
While giving someone link to post on their site, instead of
<a href="www.mysite.com"><img sre="mybanner.jpg"></a>, give
<a href="www.mysite.com/click.php?url=page.html"><img sre="mybanner.jpg"></a>
Try it out.

No comments:

Post a Comment