Log in

View Full Version : Hit Counter?



ChampJames.
19-02-2008, 08:22 PM
I need a hit counter for my website, but I dont want to use one of these free ones that you have to include an advert with.

Could anybody supple me with the code that I can use to get a hit counter to appear on my page, or link me to a website that offers such a service.

--ss--
19-02-2008, 08:28 PM
Here an basic PHP one which I normally use:


<?php
$document = ("hits.txt");
$hits = file($document);
$hits[0] ++;
$fp = fopen($document , "w+");
fputs($fp , "$hits[0]");
fclose($fp);

echo("The Message you want showed: $hits[0]");
?>
Create an .txt file called hits.txt and change the permissions to 777 ;).

Decode
19-02-2008, 08:30 PM
Its simple to make a php counter;

make a file called counter.txt, write the number "1" in it and save it.

Then make a file called counter.php and add this code to it;



<?php

$filename = "counter.txt";
$fd = fopen ($filename, "r");
$contents = fread ($fd, filesize($filename));
fclose ($fd);
$contents=$contents+1;
echo $contents;

$fp = fopen ($filename, "w")
fwrite ($fp,$contents);
fclose ($fp);
?>


Now use a php include to include counter.php to your website :)

ChampJames.
19-02-2008, 08:34 PM
thanks.

Want to hide these adverts? Register an account for free!