<?PHP
/*
Example of a internal counter with stats
TEST STEP 1
-- create the database and increments the counter
redir.php?url=index.html - will redir index.html, add +1 to counter
redir.php?url=http://www.altavista.com - will open altavista, add +1 to the counter
TEST STEP 2
-- view the stats
redir.php?stats=password
*/
if (!empty($url) || !empty($stats)) {
// set to 0 if running under windows
$config[lockfiles] = 1;
// the password
$config[password] = "password";
// the file will be save
$config[database] = 'redir.dat';
// the SimpleDB
include_once ("db.php");
$SimpleDB = new SimpleDB;
$SimpleDB->filename = $config[database];
$SimpleDB->lockfiles = $config[lockfiles];
$db = $SimpleDB->db_get();
// If the DB open continue
if ($db !== FALSE) {
if (!empty($url)) {
//increse counter
$db[$url]++;
//write db
$write = $SimpleDB->db_write($db);
//redirect
header("Location: $url");
}
// the stats part
elseif ($stats == $config[password]) {
reset($db);
asort($db);
$db = array_reverse($db);
print "<table border=1>";
while (list($a,$b) = each($db)) {
print "<tr><td>$a</td><td>$b</td></tr>\n";
}
print "</table>";
}
}
else {
print "Cant Open the Database";
exit;
}
}
?>
|