Thursday, June 2, 2011

A Counter Script In PHP


Below given script can be used as a counter.The value of the counter variable($dat) will be incremented each time it executes..


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);
}


No comments:

Post a Comment