Main Menu

HOME

.Net
ASP
Assembly
C
C++
Delphi
HTML
Java
JavaScript
MySQL
PC interface
Powershell
Perl
PHP
VBScript
Visual Basic
XML

Make money selling software. Check this out here

Hosted clickbank mall. Check this out here




   Misc

   Amazon

   Links

    


A Graphical Counter in PHP
 

 

  First you need some counter artwork , we suggest counterart for some fine examples
Create a file in this example it is called counter.txt and enter a starting number.
Upload this to your server and on UNIX servers chmod to 755.
Copy the following code into a new file called grcounter.php
Insert the following code on the page where you wish the counter to appear.

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

Thats it.


<?php
//create a file called counter.txt and upload it to your server
//now open the file
$fp = fopen("counter.txt" , "r");
//read in the current count
$count = (int)fread($fp, 1024);
//increment the count by 1
$count++;
//close the file
fclose($fp);
//image display, get the lentgth of the count
for ($i = 0 ;$i < strlen($count) ; $i++)
{
$imgsrc = substr($count,$i ,1);
//display the image(s) note our images are in a folder located at
//images/count1/ change this to your location
echo "<img src =\"/count/01/" . $imgsrc . ".gif\">";
}
//open the counter file
$fp = fopen("counter.txt", "w");
//write the new count to the file
fwrite($fp, $count);
//close the file
fclose($fp);
?>

And below you can see this in action


 

 


Warning: fopen(mycount.txt) [function.fopen]: failed to open stream: No such file or directory in /home/program/public_html/grcounter.php on line 4
cannot open file