<?php
/***************************************************************************
* click.php
* -------------------
* begin : Monday, Jan 30, 2006
* copyright : (C) 2006 MaxProgramming, LLC
* email : [email protected]
*
***************************************************************************/
import_request_variables('GPC'); // In case register_globals = OFF in php.ini
//--SETTINGS--------------------------------------------------------------------
$filename = 'click.dat'; // Data file path
$filename_country = 'country.dat'; // Data file path
$filename_system = 'system.dat'; // Data file path
$password = 'admin'; // Admin panel password
//--SCRIPT----------------------------------------------------------------------
if (file_exists($filename)) {
$handle = fopen($filename, "r+"); //The file $filename exists
} else {
$handle = fopen($filename, "a+"); //The file $filename doesn't exists
rewind($handle);
}
$fcontents = file($filename);
if (file_exists($filename_country)) {
$handle_country = fopen($filename_country, "r+"); //The file $filename_country exists
} else {
$handle_country = fopen($filename_country, "a+"); //The file $filename_country doesn't exists
rewind($handle_country);
}
$fcontents_country = file($filename_country);
if (file_exists($filename_system)) {
$handle_system = fopen($filename_system, "r+"); //The file $filename_system exists
} else {
$handle_system = fopen($filename_system, "a+"); //The file $filename_system doesn't exists
rewind($handle_system);
}
$fcontents_system = file($filename_system);
if ($admin == $password) {
$page .= "<html>\n";
$page .= "<head><title>Admin Page</title></head>\n";
$page .= "<body bgcolor=#ffaa04>\n";
$page .= "<table border=1 cellpadding=5 cellspacing=0>\n";
$page .= "<tr bgcolor=#0703A9>\n";
$page .= "<td colspan=2><font size=3 face=arial color=white><b>Click Count Statistics</b></font></td>\n";
$page .= "</tr>\n";
$page .= "<tr bgcolor=#999999>\n";
$page .= "<td><font size=2 face=arial><B>URL</td>\n";
$page .= "<td align=center><font size=2 face=arial><B>Clicks</td>\n";
$page .= "</tr>\n";
while (list ($line_num, $line) = each ($fcontents)) { // while there are elements in the array
list($url, $count) = split('\|', $line);
$page .= "<tr bgcolor=#dddddd><td><font size=2 face=arial><a href=\"$url\" target=\"_blank\">$url</a></td><td align=center><font size=2 face=arial>$count</td><tr>\n";
}
$page .= "</table>\n";
$page .= "<br>\n";
// ------------------------------ Display Country Statistics
$page .= "<table border=1 cellpadding=5 cellspacing=0>\n";
$page .= "<tr bgcolor=#0703A9>\n";
$page .= "<td colspan=2><font size=3 face=arial color=white><b>Country Statistics</b></font></td>\n";
$page .= "</tr>\n";
$page .= "<tr bgcolor=#999999>\n";
$page .= "<td><font size=2 face=arial><B>Country</td>\n";
$page .= "<td align=center><font size=2 face=arial><B>Clicks</td>\n";
$page .= "</tr>\n";
while (list ($line_num, $line) = each ($fcontents_country)) { // while there are elements in the array
list($data, $count) = split('\|', $line);
$page .= "<tr bgcolor=#dddddd><td><font size=2 face=arial>$data</td><td align=center><font size=2 face=arial>$count</td><tr>\n";
}
$page .= "</table>\n";
$page .= "<br>\n";
// ------------------------------ Display Operating System Statistics
$page .= "<table border=1 cellpadding=5 cellspacing=0>\n";
$page .= "<tr bgcolor=#0703A9>\n";
$page .= "<td colspan=2><font size=3 face=arial color=white><b>Operating System Statistics</b></font></td>\n";
$page .= "</tr>\n";
$page .= "<tr bgcolor=#999999>\n";
$page .= "<td><font size=2 face=arial><B>Operating System</td>\n";
$page .= "<td align=center><font size=2 face=arial><B>Clicks</td>\n";
$page .= "</tr>\n";
while (list ($line_num, $line) = each ($fcontents_system)) { // while there are elements in the array
list($data, $count) = split('\|', $line);
$page .= "<tr bgcolor=#dddddd><td><font size=2 face=arial>$data</td><td align=center><font size=2 face=arial>$count</td><tr>\n";
}
$page .= "</table>\n";
$page .= "</body>\n";
$page .= "</html>\n";
echo $page;
} else {
// ------------------------------ We log the country
if ($country <> "") {
$exists = False;
while (list ($line_num, $line) = each ($fcontents_country)) { // while there are elements in the array
list($data, $count) = split('\|', $line);
$count = str_replace("\n", "", $count);
if (strcmp($data, $country) == 0) {
//$count = intval($count);
$count++;
$exists = True;
}
if ($line_num > '0') { $newcontents_country .= "\n"; }
$newcontents_country .= "$data|$count";
}
if (!$exists) {
if ($newcontents_country <> "") { $newcontents_country .="\n"; }
$count = 1;
$newcontents_country .= "$country|$count";
}
if (flock($handle_country, LOCK_EX)) {
fputs($handle_country, $newcontents_country);
flock($handle_country, LOCK_UN);
}
fclose($handle_country);
}
// ------------------------------ We log the operating system
if ($system <> "") {
$exists = False;
while (list ($line_num, $line) = each ($fcontents_system)) { // while there are elements in the array
list($data, $count) = split('\|', $line);
$count = str_replace("\n", "", $count);
if (strcmp($data, $system) == 0) {
//$count = intval($count);
$count++;
$exists = True;
}
if ($line_num > '0') { $newcontents_system .= "\n"; }
$newcontents_system .= "$data|$count";
}
if (!$exists) {
if ($newcontents_system <> "") { $newcontents_system .="\n"; }
$count = 1;
$newcontents_system .= "$system|$count";
}
if (flock($handle_system, LOCK_EX)) {
fputs($handle_system, $newcontents_system);
flock($handle_system, LOCK_UN);
}
fclose($handle_system);
}
// ------------------------------ We log the URL that was clicked
if ($link <> "") {
$exists = False;
while (list ($line_num, $line) = each ($fcontents)) { // while there are elements in the array
list($url, $count) = split('\|', $line);
$count = str_replace("\n", "", $count);
if (strcmp($url, $link) == 0) {
//$count = intval($count);
$count++;
$exists = True;
}
if ($line_num > '0') { $newcontents .= "\n"; }
$newcontents .= "$url|$count";
}
if (!$exists) {
if ($newcontents <> "") { $newcontents .="\n"; }
$count = 1;
$newcontents .= "$link|$count";
}
if (flock($handle, LOCK_EX)) {
fputs($handle, $newcontents);
flock($handle, LOCK_UN);
}
fclose($handle);
if ( $forward == "no" ) {
//Do nothing
} else {
header("Location: $link");
}
}
}
?>