PHP : Simple Graphical Hit Counter

PHP Logo Like said in the post before Yesterday evening I have been working on this tutorial, I think that the ease of use of this counter will make it so special, you can implent it anywhere on the website just by calling a file as an image! confused? I show you :
<img src=’counter/counter.php’ />
See that? we are calling an PHP file as an image. The end result is an smooth looking image that shows how many times an page or website has been seen,just like This script will work on almost any server, the only requirements are to have the GD Library installed on the server.

Before I show you the script I explain some aspects of it.

The first thing to know is that the font(text) for the counter is generated from an external image, I have choson for this because it looks better than using clear type fonts, specially when the text is this small.

Second to know is that you can modify all the colors/borders/text position look in counter.php between line 36-50 all variables are set here.

Lets tear it apart.
From line 11 to 16 , we look for the file hits.txt we open it, and read the value that is inside. we add 1 to that value and close it.

From line 36 to 50 , like said before we can set all the variables to customize its looks.

	$outerBorder 		= "666666";
	$innerBorder 		= "ffffff";
	// the spacer between left and right.
	$barPosition 		= 24;
	// LEFT
	$leftFill 		= "ff6600";
	// remember to leave strtoupper("")
	$leftText 		= strtoupper("HITS");
	$leftTextColor 		= "000000";
	$leftTextPosition 	= 4;
	// RIGHT
	$rightFill 		= "898E79";
	$rightText 		= strtoupper($hits);
	$rightTextColor 	= "000000";
	$rightTextPosition 	= 27;

From line 62 to 105, we set the location (x,y) of the characters in font.png
From line 108 to 119 we prepare the left side of the image.
From line 121 to 133 we prepare the right side of the image.
On line 140 we call the Function and draw the image.

DrawButton($hits);

And this is what the image looks like :
download file here you can download it!

I hope you like it ! Last but not least. I’d appreciate it if you leave me a comment when you are going to use it! thanks in advance.. have any ideas to make this script nicer? hey let me know!

And if you really like it, digg it orĀ  stumble it or clip it or …. well you get the point!

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • Facebook
  • Google
  • Furl
  • Live
  • Ma.gnolia
  • NewsVine
  • StumbleUpon
  • Technorati
  • TwitThis
  • Chawlk
  • Propeller
  • Ycombinator
Tags: , ,

Leave a Reply