Im asking for help to add a counter for my link redirect code.
The link redirect code looks like this:
<?
$id = preg_replace("/[^0-9]/","",$_GET['id']);
$x[101] = "http://www.ebay.com";
$x[102] = "http://www.google.com";
$x[103] = "http://wikileaks.org";
$x[104] = "http://potato.com";
if (isset($x[$id])){}
else {
die (header("Location: http://www.google.com"));}
header("Location: $x[$id]");
exit;
?>
That code lies in a file called link.php, and then I use links like www.mysite.com/links.php?id=103 . When someone clicks that link the code will direct them to http://wikileaks.org.
Now what im looking for is to count the hits for the different links 101 to 104 without using mysql.
Maybe something like this? http://www.stevedawson.com/scripts/text-counter.php
<?php
if (file_exists('count_file.txt'))
{
$fil = fopen('count_file.txt', r);
$dat = fread($fil, filesize('count_file.txt'));
echo $dat+1;
fclose($fil);
$fil = fopen('count_file.txt', w);
fwrite($fil, $dat+1);
}
else
{
$fil = fopen('count_file.txt', w);
fwrite($fil, 1);
echo '1';
fclose($fil);
}
?>
I have no idea how to add it to my redirect code, and also hopefully make it work for all the links. Counting each link, and hopefully not creating a 100 different text files, as the real site has lots more links than my example code above. Any ideas?