Free Webmaster Resources .info
PHP Introduction and Tutorials Javascript  Introduction and Tutorials HTML  Introduction and Tutorials ASP  Introduction and Tutorials Free Internet Access Guide and Directory Webspace  Directory Webhosting  Directory Adult Webhosting  Directory PHP Hosting  Directory ASP Hosting  Directory
à Navigation
» Home
» Php Introduction
» Php Tutorials
» Submit Scripts
 
Subscribe for free!

Join our mailing list today and recieve free updates monthly with web hosting specials!
 
 

 

 

Free Webmaster Resources .info | Free PHP Tutorials


Building Counters

For this tutorial we will show you how to build a simple counter for your website .

The basis of a counter is the same in most languages , create a text file to hold the count , then we read the file , increment the count , open the text file , store the new count and then close the file .

<?php
//this is our text file if you create a different
//named file change the script below to reflect this
$counter_file = ("mycount.txt");
//now we open the file
$visits = file($counter_file);
//this increments the counter value by 1
$visits[0]++;
//now we will open the counter file for
//writing "w"
$fp = fopen($counter_file , "w");
//put the new count value into the counter
//file
fputs($fp , "$visits[0]");
//close the file
fclose($fp);
//display the count
echo $visits[0];
?>

And to add this to your page you enter the following where you wish the counter to appear , again if you have called your file with the script in it something other than mycounter.php , you will have to change the script to reflect this.

<?php
include ("mycounter.php");
?>

Here is the count displayed on this page.


Warning: fopen("mycount.txt", "w") - Permission denied in /home/sites/site16/web/mycounter.php on line 5

Warning: Supplied argument is not a valid File-Handle resource in /home/sites/site16/web/mycounter.php on line 6

Warning: Supplied argument is not a valid File-Handle resource in /home/sites/site16/web/mycounter.php on line 7
2070

In part 2 we will build a graphical counter and give you a couple of locations for a large amount of counter digits

[more] [1] [2]

Recommended Webhosting Company
Find free web hosting
Looking for free web hosting? Review and compare FindStuff's comprehensive resources. Search now!

 

 
Related Websites
 


Free Email
Your source to free email.

Free Casino Downloads
Contains useful free casino downloads.

Free Software Downloads
A complete collection of free software downloads.

Free
Download free stuff from psike.com your free stuff resource.

Free Teen Online Dating
Meet other singles for free online dating.

Coolfreeweb.com
The Free category at coolfreeweb.com

My Directory Listing
A massive directory listing of websites

Website Collation Project
The website collation project contains a huge directory of websites.


 
Top Webhosts
 
 1. Find free web hosting
 2. Free Web Hosting
 3. Web Hosting
 4. Free Web Hosting
 5. Web And Hosting
 
-
- Give us feedback
 
Last updated
Oct 11, 2008
Free Webmaster Resources .info | A resource must for every web master
Untitled Document - Web Hosting
- PHP Hosting
- Free Internet Access