<?php $visits = "hits.txt"; // open the file and read how many visitors was $fp = fopen($visits,"r"); $hits = (int )fgets($fp); fclose($fp); // increment the number of visitors $hits++; // open the file and write how many visitors are now $fp = fopen($visits,"w"); fputs($fp,$hits); fclose($fp); ?>
could be done with a single fopen/fclose but how is now you can see more clear how to do each step.