Re: Creating a simple hitcounter for PHP web pages. (saves to files)
- From: Michael Fesser <netizen@xxxxxx>
- Date: Fri, 30 May 2008 14:59:27 +0200
..oO(tony19760619@xxxxxxxxx)
To make this work on a single page you will need to create/modify 4
files.
So here goes...
Hmm ...
Create a file called counter.php and put following code in it:
<?php
//Counter
$count_my_page = ("hitcounter.txt");
Why the parentheses?
$hits = file($count_my_page);
$hits[0] ++;
$hit_count = $hits[0];
$fp = fopen($count_my_page , "w");
fputs($fp , "$hits[0]");
Why the double quotes?
fclose($fp);
//echo $hits[0];
What about file locking and prevention of simple page reloads?
//Details to add to list
$count_my_page = ("hitcounter.csv");
$fp = fopen($count_my_page , "a");
$ip=$_SERVER[REMOTE_ADDR];
Missing single quotes.
$dnsname = gethostbyaddr($ip);
$referer=$_SERVER[HTTP_REFERER];
$page=$_SERVER[PHP_SELF];
Same here. Check your error_reporting, you'll get at least three
E_NOTICE errors.
$now = date( "Y/m/d H:i:s", time() );
fputs($fp , "$now,$hit_count,$page,$ip,$dnsname,$referer\r\n");
fclose($fp);
?>
Micha
.
- References:
- Creating a simple hitcounter for PHP web pages. (saves to files)
- From: tony19760619
- Creating a simple hitcounter for PHP web pages. (saves to files)
- Prev by Date: Creating a simple hitcounter for PHP web pages. (saves to files)
- Next by Date: Where is the email address?
- Previous by thread: Creating a simple hitcounter for PHP web pages. (saves to files)
- Next by thread: Where is the email address?
- Index(es):
Relevant Pages
|