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;

<?PHP

$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

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? :-/

try the full path, with the C:\ included

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.