Been scouring the web for ages and can't find a solution. So here I am.....

Firstly this is my first venture into web design and hosting. I've got my own site running from just my laptop atm. I'm trying to include a basic hit counter using the following code;


$filename = "counter.txt" ;
$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) ;


But when I try visiting the site I get the following error message;

"Warning: fopen(counter.txt) [function.fopen]: failed to open stream: No such file or directory in C:\xampp\htdocs\index.php on line 19
Can�t open counter.txt"

If anyone can help it would be much appreciated..

Thanks in advance

8 Years
Discussion Span
Last Post by kylegetson

the counter.txt file does not exist. create the file first, and make sure its writable by the webserver.


The counter.txt files is created and in my root folder. I'm not sure on how to make it editable by the server though? :-/

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.