Tuesday, December 9, 2008

Php- Create simple counter using cookie

Simple counter using cookie

$counterFile = "/home/httpd/html/counter/counter.text";

function displayCounter($counterFile) {
global $counted
$fp = fopen($counterFile,rw);
$num = fgets($fp,5);
if (!$counted) {
$num += 1;
unlink("$counterFile");
exec("echo $num > $counterFile");
}
print "$num";
}

if (!file_exists($counterFile)) {
exec("echo 1 > $counterFile");
}

displayCounter($counterFile);
?>


/* Add the following to the very top of the page you want to count */



No comments: