My php classes was trying to build a counter in PHP using a file (it’s from a book). The problem we are running into is that if we place 0 into the file, it will not get the file. Can anyone suggest a way around this???
This is the code
<?php $ctfile='ctr.txt'; $FILEH = fopen($ctfile, 'r+') or die ("Cannot open $ctfile"); flock($FILEH, LOCK_EX) or die ("Cannot lock file $ctfile"); $ctr=fgets($FILEH) or die ("Cannot get $ctfile"); $ctr= rtrim($ctr, 'n'); if (is_numeric($ctr)) { $count=$ctr +1; rewind($FILEH); $ret=fputs($FILEH, $count); print "$count"; } else { print "error: ctr-$ctr <= not a numeric value"; } fclose ($FILEH); ?>