Webpage Counter

Code:
<?php
$fp=fopen("hits.txt","r");
$count=fgets($fp,1024);
fclose($fp);
$fp=fopen("hits.txt", "w");
$count++;
fputs($fp, $count);
fclose($fp); 
echo $count;
?>

Oh and you should check your site out in Firefox. (Or not if you don't want more work to do...)

Also wrong forum i believe. And no homework threads. And use google in future.

Other than that, good luck. :)
 
Last edited:
You need to update the counter too
emot-ssh.gif
 
Whoops, had made a bit of a mistake on line 7... Updated it though now, i gave it a go and it worked fine for me. Just put that in your page where you want the number of hits to appear.

Also this assumes the file you're using to store the count in is called hits.txt, and you need to chmod it to 666.

If you just save it, and make it it's own file, you'll just get the number incrementing each time... working link
 
Back
Top Bottom