| px | top | add code | search | signup | login | help |
<? // Last Updated the 17th of Chaos (January 17th for non-dIscordians) ?>
<? // Put this at the top of the page you want to display the count
$COUNTFILE = "data/count.data";
function getcount ( $file ) {
global $COUNTFILE;
if (! file_exists($COUNTFILE)) echo("ERR:NCF"); // WTF? No Counter File
$FileData = file($COUNT_FILE) echo("ERR:CNO"); // WTF? Can Not Open
while ( list ( $key, $val ) = each ( $FileData ) ) {
if ( $val != "" ) {
list ( $TargetURL, $TargetCount ) = preg_split ( "/\t|\n/", $val );
if ( $TargetURL == $file ) echo "$TargetCount";
}
}
}
?>
<? // Place in a seperate file that you link to, to update count (click.php)
$COUNTFILE = "data/count.data";
function error ($error_message) {
echo $error_message;
exit;
}
$url = urldecode($QUERY_STRING);
if (! file_exists($COUNT_FILE))
error("Can't find file, check '\$COUNTFILE' variable ('$COUNTFILE')...");
if ((! $url) || (! preg_match("/http:/", $url)))
error ("Invalid url, you chould add url ex: <a href=\"http://$SERVER_NAME$PHP_SELF?target.php\">http://$SERVER_NAME$PHP_SELF?target.php</a>");
$file_arry = file($COUNT_FILE) or error("Can not open \$COUNTFILE ('$COUNTFILE')");
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 \$COUNTFILE ('$COUNTFILE')");
flock($fp, 1);
fputs($fp, $file);
flock($fp, 3);
fclose($fp);
header("Location: $url");
?>
Comments or questions?
PX is running PHP 5.2.11
Thanks to Miranda Productions for hosting and bandwidth.
Use of any code from PX is at your own risk.