View Full Version : Hit Counter
Mr. Bubble
10-16-2005, 02:44 AM
hello, i am a noob at php and was wondering if anybody could write a hit counter script for me..... im not sure if it should be php or javascript, so could someone please write a script for me; it only must count the number of page veiws, nothing special like IP addys or how many in 1 hour.... just how many hits
TIA,
Alex.
Nightfire
10-16-2005, 03:01 AM
Learn how to do it yourself ;) http://www.tutorialized.com/tutorials/PHP/Counters/1
GO ILLINI
10-16-2005, 09:08 PM
<?php
if(file_exists("count.dat")) {
// open for reading
$fp = fopen("count.dat", "r");
$count = fgets($fp, 1024);
$count++;
fclose($fp);
echo "there have been $count total page views.";
// open for writing
$fp = fopen("count.dat", "w");
fwrite($fp, $count);
fclose($fp);
} else {
// create a new file
$fp = fopen("count.dat", "w"); // open for writing
fwrite($fp, "1");
echo "there have been one total page views";
fclose($fp);
}
?>
works for me.
I don't do individual pages... I just do total page views of the whole site in count.dat.
Remember to change count.dat to something dirrefent like countPage1.dat
countPage2.dat
or it will give you page views over the whole site.
just make the name dirrefent on every page.
I suppose there would be some way to make a $countname variable by defining it as
$countname = REQUESTED_URI".dat"
or something.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.