PHP Affiliate Script
TWSC.biz  
WebSite Hosting TWSC.biz Design TWSC.biz Scripts TWSC Support Contact TWSC

Back HomeOrder Products and Services

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";
$fh = 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);
?>



 
Join the Post Affiliate Network here >>

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, 2008, 2009, 2010
All rights reserved
The Website Creator (TWSC.biz),
Centurion, Pretoria, South Africa