A simple counter
This is our first counter example this is ideal if you are not to fussed about knowing about user details . The first step is to create a file to store the count in this example we called our file counter1.dat and started the count at 1000 . you could call your file something else but remember and change the script accordingly.
Here is the script for this example
<?php
//simple counter example v1.0
//open the counter file in read only mode
$counterfile = "./counter1.dat";
if(!($fp = fopen($counterfile,"r"))) die ("cannot open counter file");
//read the value stored in the file
$thecount = (int) fread($fp, 20);
//close the file
fclose($fp);
//increment the count
$thecount++;
//display the count
echo "visitor no : $thecount";
//open the file again in write mode and store
// the new count
$fp = fopen($counterfile, "w");
fwrite($fp , $thecount);
//close the file
fclose($fp);
?>
|