php help

I can't seem to see their free plan? Can you provide a link of the specifications if you're not sure whether it supports php or not?
 
Sorry it was a long time before I got back to this post but I keep getting Spam.

The PHP Code for my Hit Counter is this

$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) ;

Now I know I put it into a TXT File but what name do I call this file
 
Well the easy (though not particularly nice from a programming point of view) way would be to embed that code into your HTML page, and embed that code somewhere (at the top for example) in php tags like 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) ;
?>

...rest of your HTML

If you rename that file index.php and your server supports PHP, the script should execute each time you load the page and add 1 to the counter.
 
Thanks for the help but let me see if I have it down right??

Inside my index.html page wherever I want my counter to be placed I put

<?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) ;
?>


And if my server support PHP I can leave the page as index.html and it sould work.

Do I have all this down right??
 
The code looks fine to me, at least at a quick glance. By my "almost" reply, I meant the only thing you had wrong in the previous post was the naming - it'd need to be index.php and not left as index.html.
 
I can't access that site at the moment (for reasons at my end not yours) but if you see the PHP code and you've entered it correctly then chances are your host doesn't support PHP. This doesn't overly surprise me, as i said earlier a lot of free ones don't.

As an aside why do you want a hit counter anyway? They're really not the nicest or most professional of things at all. How many good, popular and professional looking sites that you know of have them?
 
Back
Top Bottom