Simple Counter
The way the counter works:
- We create a text file to hold the count.
- Then we read the text file.
- Increment the count.
- Open the text file.
- store the new count and then close the text file.
Seems hard but actually very easy!
Create a text file, name it counter.txt
<?php
$count = ("counter.txt");
//now this is where we open the file
$visits = file($count);
//this adds 1 hit
$visits[0]++;
//Now open the counter
$fp = fopen($count , "w");
//put the new count value into the txt file
fputs($fp , "$visits[0]");
//close the file
fclose($fp);
//display the count
echo $visits[0];
?>
Save as counter.php or anything you wish
Now just upload the counter.php and counter.txt to the same dir, and command the txt file to 777
then this hould work perfect!
To add the counter to anywhere on your site just add the following code
<?php
include ("counter.php");
?>