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

Now for the second installment in our counter series , a graphical counter . This si much the same as before but of course yo need some images for your counter . Here are two great resources which I use frequentlt for my graphic counters.

Digitmania : this has a fantastic range of counter digits available to download.
Counterart : another huge range of counter digits , this is a must see

Now for the first part of the script , I thought about just using the same script as last time but then thought no we will show a different way of accessing a file , reading a file , writing to a file.

You will have to create a text file called mycount.txt and make sure this file is readable and writable .

Here is the script


<?php
//this is our file with the count in it
//note this is in the same directory as the script
$counter_file = "mycount.txt";
//now we open our file for reading
if(!($fp = fopen($counter_file , "r"))) die ("cannot open file");
//store the first 24 bytes of data from the file into $counter
$counter = (int)fread($fp, 24);
//close the file
fclose($fp);
//increment the counter by 1
$counter++;
//open the counter file for writing
$fp = fopen($counter_file , "w");
//write the new $counter value into the file
fwrite($fp, $counter);
//close the file
fclose($fp);
?>

 

Now we save this as grcounter.php and include this onto the page where we want the counter to appear like this.

<?php
//include the main part of the counter
include "grcounter.php";
?>

We have just one bit to go and this displays the graphics on the screen .

<?php
//graphics 1 stored in images directory and are
//numbered from 0.gif to 9.gif
//loop through the values of the $counter variable
//ensure that all digits are processed by using the strlen
//function to check the length of the $counter variable
for ($i = 0 ;$i < strlen($counter) ; $i++)
{
//build of our <img src> tag
$imgsrc = SubStr($counter,$i ,1);
echo "<img src =\"images/" . $imgsrc . ".gif\">";
}
?>

And here is this example in all its glory

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

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

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

And now for our second example

<?php
//graphics stored in images/1/ directory , the images
//are labelled from 0.taskbar.gif to 9.taskbar.gif
for ($i = 0 ;$i < strlen($counter) ; $i++)
{
$imgsrc = SubStr($counter,$i ,1);
echo "<img src =\"images/1/" . $imgsrc . "taskbar.gif\">";
}
?>


And finally because I like this one here is another digit example , this one is called punk


That is it for just now I hope you found this helpful.

[more] [1] [2]

Recommended Webhosting Company
free web hosting Web Hosting $4.95
Unlimited Space, Unlimited Bandwidth, Free Domain for life, Free Setup, Money-Back Guarantee, No Contracts

 

 
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. free web hosting Web Ho
 2. Web Hosting
 3. Free Web Hosting
 4. Webhosting
 5. Hosting
 
-
- Give us feedback
 
Last updated
Nov 19, 2008
Free Webmaster Resources .info | A resource must for every web master
Untitled Document - Web Hosting
- PHP Hosting
- Free Internet Access