Hit Counter using PHP files

The same file (counter.txt) is used for both reading as well as writing. So each time the file should be closed before opening for the next time as read or write mode.

<?php
$filename=”counter.txt”;
$f=fopen($filename,”r”) or die(”Read Failed”);
$str=fread($f,filesize($filename));
echo “The page has been visited for $str times since 2nd June 2009″;
fclose($f);

$f=fopen($filename, “w”) or die(”Write Failed”);
$str=$str+1;
fwrite($f,$str);
fclose($f);
?>

Comments

Popular posts from this blog

Installing ns3 in Ubuntu 22.04 | Complete Instructions

How to Create Ubuntu 24.04 Bootable USB Using Rufus [Step-by-Step Guide]

Installation of NS2 in Ubuntu 22.04 | NS2 Tutorial 2