PHP Hit Counter

  Fr0z3n 13:19 01 Oct 2004

Can any1 help me here?
I want to track the number of hits on the index.php page of my site, but want to display the results on /stats.php .

Any1 know of a good script of method to achieve this?

The site is: click here

I want to counter the number of hits on the above address and display this number on click here .

Thanks for help in advance.

  Fr0z3n 17:44 01 Oct 2004


  harristweed 19:24 01 Oct 2004

On the index page put a script that writes the number of hits to a file then read the file on the second page.

Ssuggested script:

// start session
header("Cache-control: private");// IE6 Fix
//if session_count not =1 then open file and advance hit_counter
$counter_file = "count.txt";
if(!($fp = fopen($counter_file, "r")));
$counter = (int) fread($fp, 20);
// advance counter
// write new number to counter

$fp = fopen($counter_file, "w");
fwrite($fp, $counter);
// assign value of 1 to session variable

Then read the text file on second page

Hope that helps

  Fr0z3n 19:27 01 Oct 2004

can u please explain exactrly how to do this cuz im sorta a bit new to php.

  harristweed 09:31 02 Oct 2004

I'd love to teach you php but it has taken me three years so far and i'm sorry but I really don't have that much free time.

Read this tutorial

click here

then use a text file instead of mysql

Search the web for php tutorials there are a book

Beginning PHP4 by wrox is good - get it on Amazon

You can read the PHP manual here
click here

or get a script already written, 55 counter scripts here
click here

  blackheart 09:28 03 Oct 2004

I'm using a free hit counter on my website, it involves no scripting on your part and you can find it at click here.

You shouldn't have any problems.

If you fancy learning some php/MySQL basics, try Larry Ullmans book: PHP and MySQL for dynamic websites. It's quite basic but I've only read that book and I wrote a functioning guestbook I recomend it, yeah.

This thread is now locked and can not be replied to.

Elsewhere on IDG sites

iMac Pro review

25 book design and illustration tips

iMac Pro review

Idées cadeaux pour geeks et tech addicts