PHP Hit Counter

  Fr0z3n 13:19 01 Oct 04
Locked

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 04

:(

  harristweed 19:24 01 Oct 04

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:

<?php
session_start();
// start session
header("Cache-control: private");// IE6 Fix
if(!$_SESSION['count']){
//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);
fclose($fp);
// advance counter
$counter++;
// write new number to counter

$fp = fopen($counter_file, "w");
fwrite($fp, $counter);
fclose($fp);
// assign value of 1 to session variable
$_SESSION['count']=1;
}


Then read the text file on second page

Hope that helps

  Fr0z3n 19:27 01 Oct 04

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

  harristweed 09:31 02 Oct 04

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 loads....buy 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 04

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 script...so I recomend it, yeah.

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

How to get Windows 10 for free | How to install Windows 10: There is still a way to avoid paying…

1995-2015: How technology has changed the world in 20 years

Alex Chinneck’s giant ice cube Christmas tree at Kings Cross

Apple rumours & predictions 2017: The iPhone 8, new iPads, and everything else you should expect fr7…