$digits = 4; $filelocation="count.txt"; if (!file_exists($filelocation)) { $newfile = fopen($filelocation,"w+"); $content=1; fwrite($newfile, $content); fclose($newfile); } $newfile = fopen($filelocation,"r"); $content = fread($newfile, filesize($filelocation)); fclose($newfile); $newfile = fopen($filelocation,"w+"); if (!$c){ $content++; } fwrite($newfile, $content); fclose($newfile); echo "".sprintf ("%100"."$digits"."d",$content).""; ?>