TWSC Tutorial Series

Simple PHP Counter
This is a simple counter to count the number of visitors to any page on your website.
* Copy and paste the code below into NOTEPAD.
* Save it as counter.php
* Upload counter.php in ASCII mode to your server
* Upload an empty file called index.php.dat to your server
* CHMOD index.php.dat to 777
* Call the script from within your index.php page with:
<? include "counter.php" ?>
* If you want to count hits on a page called order.php, then your .dat filename should be order.php.dat
counter.php
<?
$cfile = basename($PHP_SELF) . ".dat";
= fopen($cfile, "r+");
if (!$fh) {
die("<br>Failed to open file.");
}
$s = fgets($fh, 6);
$count = (int) $s;
$count = $count + 1;
$count = str_pad($count, 6);
rewind($fh);
fwrite($fh, $count);
echo "<center>$count visitors to this
webpage</center>";
fclose($fh);
?> |

|
|
|
TWSC.biz Hosting |
Order Hosting |
Domain Registration |
TWSC Affiliate Lite |
Affiliate Login
Software Search |
Affiliate Tracking Software
Services provided by The Website Creator (TWSC.biz) Sold by 2Checkout.com (Ohio)
© 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007 All rights reserved
The Website Creator (TWSC),
Makateeskop Estates, PO Box 340, Paulpietersburg, 3180, KZN, South Africa
|
|