Your Ad Here

 Navigation
Home
Source code
Tutorials
RSS feeds
Articles
Wordpress plugins
Blog
Books
Software
Downloads
Hosting
manuals
Script directory
Training
Our Links




 Sponsors
 Links
golfing products
dropshippers
domain names
 Downloads
 Misc
Webmaster Resources
Only PHP
ScriptSearch.com
Scripts.com - Get the best scripts NOW!
AndreaPHP Programming

Valid XHTML 1.0 Transitional


Valid CSS!


Building Counters


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.

3586

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

Forward to Part 2




Books
 Sponsors
 Random Code
Java version with php(php and java)
Mozilla or Internet explorer(internet)
Random URLs(randomizing)
 Random Article
  Network
Programming resources
Tutorials directory
Clickbank mall
sell software
Free auctions, low cost stores
UK products
US products
Gambling directory
Sexy free wallpapers
Hosting resources
ASP site
DVD site
Domain names
Dating site
Software directory
Maxi directory
bigarticle : free articles




beginners PHP Copyright © 2004 onwards by beginnersPHP.