Home arrow PHP arrow Page 5 - Making Usage Statistics in PHP
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
TABLE OF CONTENTS:
  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
SEARCH DEVARTICLES

Making Usage Statistics in PHP - Creating the Image Library
(Page 5 of 7 )

Having the data, let's start to deal with the image creation library of PHP (GD). Its output is GIF/PNG/JPEG. It uses image resources.  These are PHP variables representing images. Usually, in a program there is only one image resource. You can create an image resource using one of the following functions:

  1. ImageCreate (int width, int height) - Creates a blank image resource
  2. ImageCreateTrueColor (int width, int height) - Creates a blank true color image resource
  3. ImageCreateFromGIF (string filename) - Creates an image resource using a given picture file
  4. ImageCreateFromJPEG (string filename) - Creates an image resource using a given picture file
  5. ImageCreateFromPNG (string filename) - Creates an image resource using a given picture file

This code can be good for this, but don't forget to call the header function because it's not HTML output!


header('Content-type: image/png');
$image
=imagecreate(400,210); 

Then you can start to draw the picture. Here are some of the functions - read them as we will use some to make the Top 10 stats. For more, see the PHP manual.

  1. ImageColorAllocate (resource image, int red, int green, int blue) - Prepares an RGB color to use
  2. ImageLine (resource image, int x1, int y1, int x2, int y2, int color) - Draws a line
  3. ImageRectangle (resource image, int x1, int y1, int x2, int y2, int col) - Draws a rectangle
  4. ImagePolygon (resource image, array points, int num_points, int color) - Draws a polygon using an array
  5. ImageFilledRectangle (resource image, int x1, int y1, int x2, int y2, int color) - Draws a filled rectangle
  6. ImageTTFText (resource image, int size, int angle, int x, int y, int color, string fontfile, string text) - Draws a TrueType text

Below you can read the code. It can be a little confusing, especially the numeric expressions, because you have to think in X and Y coordinates. But try it, you'll get the hang of it!


blog comments powered by Disqus
PHP ARTICLES

- 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 
Support 

Developer Shed Affiliates

 




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