« How much information do we have in the world? // The System for Evaluating and Monitoring Social Development Programs and Policies: the case of the Ministry of Social Development and the Fight against Hunger in Brazil »
PHP file counter (no database)
Posted on June 6th, 2008 by Fred
This script show you how to create a simple website counter using a file.
Create a file (counter.txt), containing the initial number 0 and save it as counter.txt.
Upload it to your server
CHMOD it to 777.
It will look like this:
0
The code:
//Print the current count
$File = “counter.txt”;
$counter = fopen($File, ‘r+’) ;
$data = fread($counter, 512) ;
$count = $data + 1;
print $count;
//Update the Text File With The New Count
fseek($counter, 0) ;
fwrite($counter, $count) ;
fclose($counter) ;
Very simple and easy to use… thank you very much. Please check out my webcounter it’s free!