<?php $filename = "lavender_tea_gifts"; $month = date("m"); $filename = "../counters/".$month.$filename; # set or create variables $previous=0; $filename = $filename.".txt"; # test for file and if found increment by one if(file_exists($filename)) { $filePointer = fopen($filename, "r"); $previous = fgets($filePointer,7); $previous = $previous + 1; fclose($filePointer); $filePointer = fopen($filename, "w"); fputs($filePointer, $previous,7); fclose($filePointer); } else { # write file if file does not exist $filePointer = fopen($filename, "w"); $previous = 1; fputs($filePointer, $previous, 7); fclose($filePointer); } ?>

Related Links