Forum Moderators: phranque
script code (click_counter.php)
<?php// Necessary Variables:
$COUNT_FILE = "clicks_counter_data.txt";
// En: Absolute path and name to count data file.
function error ($error_message) {
echo $error_message."<BR>";
exit;
}
$url = urldecode($QUERY_STRING);
if (! file_exists($COUNT_FILE))
error("Can't find file, check '\$COUNT_FILE' var...");
if ((! $url) ¦¦ (! preg_match("/http:/", $url))) error ("Invalid url, you chould add url ex: <A HREF=\"http://$SERVER_NAME$PHP_SELF?http://www.example.org/\">http://$SERVER_NAME$PHP_SELF?http://www.example.org/</A>");
$file_arry = file($COUNT_FILE); //or error("Can not open \$COUNT_FILE");
while (list($key, $val) = each($file_arry)) {
if ($val!= "") {
list($file_url, $nb) = preg_split("/\t¦\n/", $val);
if ($file_url == $url) {
$nb++; $file_arry[$key] = "$file_url\t$nb\n"; $find = 1;
}
}
}
$file = join ("", $file_arry);
if (! $find) $file .= "$url\t1\n";
$fp = fopen("$COUNT_FILE", "w"); //or error("Can not open \$COUNT_FILE");
flock($fp, 1);
fputs($fp, $file);
flock($fp, 3);
fclose($fp);
header("Location: $url");
?>
It worked great until past week, suddenly start failing.
In case be a security issue what can I do?
[edited by: jatar_k at 9:34 pm (utc) on Feb. 27, 2006]
[edit reason] examplified url [/edit]