...

Simple Hit counter

markjon
10-13-2008, 12:53 PM
A hit counter will let us know how many times a page is accessed. In case one visitors loads the page several times, the hit counter will increase several times (but this is likely to happen only a few times).

The code for the hit counter bellow will save the number of hits in a file named counter.txt (the name of this file may be changed). Each time the page is loaded, the file will be read, the number will be increased by one and the new number will be saved to the same file.

<?php

//The file where number of hits will be saved; name may be changed; p.e. "/counter_files/counter1.txt"
$counterfile = "counter.txt";

// Opening the file; number of hit is stored in variable $hits
$fp = fopen($counterfile,"r");
$hits = fgets($fp,100);
fclose($fp);

//increading number of hits
$hits++;

//saving number of hits
$fp = fopen($counterfile,"w");
fputs($fp, $hits);
fclose($fp);

//printing hits; you may remove next line (and keep the counter only for your records)
print $hits;

?>
To use this code, copy it to your page in the exact position where you want to show number of hits.

mlseim
10-13-2008, 02:01 PM
Who cares about hit counters anymore?

My server logs and web stats provide me with all the info I need.
The users don't care because I can make that number say anything I want it to say.

Inigoesdr
10-13-2008, 03:10 PM
Who cares about hit counters anymore?

My server logs and web stats provide me with all the info I need.
The users don't care because I can make that number say anything I want it to say.

Now, now; Don't be jealous you didn't think of it first. :p

pauls74462
01-13-2009, 10:57 PM
$hits++;


Does '$hits++;' and '$hits = $hits + 1;' do the same thing?

kbluhm
01-13-2009, 11:35 PM
Does '$hits++;' and '$hits = $hits + 1;' do the same thing?

Yes..



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum