Creating a simple hitcounter for PHP web pages. (saves to files)
- From: tony19760619@xxxxxxxxx
- Date: Fri, 30 May 2008 05:28:53 -0700 (PDT)
To make this work on a single page you will need to create/modify 4
files.
So here goes...
Create a file called counter.php and put following code in it:
<?php
//Counter
$count_my_page = ("hitcounter.txt");
$hits = file($count_my_page);
$hits[0] ++;
$hit_count = $hits[0];
$fp = fopen($count_my_page , "w");
fputs($fp , "$hits[0]");
fclose($fp);
//echo $hits[0];
//Details to add to list
$count_my_page = ("hitcounter.csv");
$fp = fopen($count_my_page , "a");
$ip=$_SERVER[REMOTE_ADDR];
$dnsname = gethostbyaddr($ip);
$referer=$_SERVER[HTTP_REFERER];
$page=$_SERVER[PHP_SELF];
$now = date( "Y/m/d H:i:s", time() );
fputs($fp , "$now,$hit_count,$page,$ip,$dnsname,$referer\r\n");
fclose($fp);
?>
Then create a file called hitcounter.txt and put value 0 in it.
Then create a file called hitcounter.csv and put following text in it:
TimeStamp,Count,Page,IP-Adress,DNS,Referer
Remember to give write permitions to the hitcounter files for your
local internet account and you done.
Now on every PHP web page you have add the following code between the
<header></header> or <body></body> tags:
<?php include ("counter.php"); ?>
If you link .csv file to excel when you click on the csv file you will
be promted to open it with excel.
If you do you get a nice grid layout of the data.
.
- Follow-Ups:
- Re: Creating a simple hitcounter for PHP web pages. (saves to files)
- From: Michael Fesser
- Re: Creating a simple hitcounter for PHP web pages. (saves to files)
- Prev by Date: Re: SQL Buddy - decent replacement for phpMyAdmin
- Next by Date: Re: Creating a simple hitcounter for PHP web pages. (saves to files)
- Previous by thread: Eclipse PHP IDE Video Tutorials
- Next by thread: Re: Creating a simple hitcounter for PHP web pages. (saves to files)
- Index(es):
Relevant Pages
|