PHP refresh detection?

Nik

New member
right firstly here is my code

<?php
$filename = "counter" ;
$fd = fopen ($filename , "r") or die ("Can't open $filename") ;
$fstring = fread ($fd , filesize ($filename)) ;
echo "$fstring" ;
fclose($fd) ;
$fd = fopen ($filename , "w") or die ("Can't open $filename") ;
$fcounted = $fstring + 1 ;
$fout= fwrite ($fd , $fcounted ) ;
fclose($fd) ;
?>

I know exactly how this code works and it works fine with one flaw which is the code is designed to add 1 to a file and display the file it adds 1 to the file on load but this also counts for a refresh how do I stop it adding 1 if the page is refreshed but to only add 1 if it is a first time load.

thanks
By the way I have heard of the method of using javascript to add 1 to a field hidden of course and php reads this field if it is 1 or less it adds 1 to the file 2 plus it doesn't how would that be implemented
 
Back
Top