Home arrow PHP arrow Page 7 - Making Usage Statistics in PHP

Making Usage Statistics in PHP

Making usage statistics on a web site is one of the most enjoyable things for me on the Internet. Thanks to the technology, you can see each click of each visitor, the date of the visiting, and how many seconds the user was reading your site. I use this feature to track which of my articles was read for the longest time. In this article I will show you how to store the statistics in a MySQL database, show the web stats in an HTML table and make figures based on the stats using the GD library. 

Author Info:
By: Adam Szanto
Rating: 4 stars4 stars4 stars4 stars4 stars / 145
February 16, 2004
  1. · Making Usage Statistics in PHP
  2. · Save the HTML Title
  3. · Showing the Statistics Table
  4. · Showing Figures Based on the Statistics
  5. · Creating the Image Library
  6. · Charting the Results
  7. · Before Saying Goodbye

print this article

Making Usage Statistics in PHP - Before Saying Goodbye
(Page 7 of 7 )

Put the picture making part of your program to the beginning of your main PHP that produces HTML output! Use the isset() function that makes you able to check whether a variable is set or not.

An example: you have a huge code in an index.php file with an if (isset($gd)) condition at the beginning. The output of the index.php is HTML, if there's no $gd set and if there is, then the output is image. Imagine that you can include pictures with echoing a simple <img src=?gd=> tag. My favourite usage of this is the code below (thanks to Jack Shieh). It shows a thumbnail of the images stored in a MySQL table.

if (isset($pic_id)) {
='SELECT Picture FROM images WHERE ID='.$pic_id;
=mysql_query($q) or print(mysql_error());
header("Content-type: image/jpeg");
$size=80// new image width
   $width=imagesx($src); $height=imagesy($src);
$aspect_ratio $height/$width;
   if (
$width <= $size) {
} else {
abs($new_w $aspect_ratio);
$img imagecreatetruecolor($new_w,$new_h);
$q='SELECT ID FROM images';
=mysql_query($q) or print(mysql_error());
"<table width=100%><tr>";
while (
echo "<td><img src=?pic_id=".$ids['ID']."></td>n";


I hope that now you can track your visitors and make graphical statistics easily as well. I wish you the experience of being visited - and I wish you saw your success also in the statistics!


DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

blog comments powered by Disqus

- Removing Singletons in PHP
- Singletons in PHP
- Implement Facebook Javascript SDK with PHP
- Making Usage Statistics in PHP
- Installing PHP under Windows: Further Config...
- File Version Management in PHP
- Statistical View of Data in a Clustered Bar ...
- Creating a Multi-File Upload Script in PHP
- Executing Microsoft SQL Server Stored Proced...
- Code 10x More Efficiently Using Data Access ...
- A Few Tips for Speeding Up PHP Code
- The Modular Web Page
- Quick E-Commerce with PHP and PayPal
- Regression Testing With JMeter
- Building an Iterator with PHP

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 

Developer Shed Affiliates


© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials