SunQuest
 
       PHP
  Home arrow PHP arrow Page 7 - Making Usage Statistics in PHP
IBM developerWorks
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Dedicated Servers  
Actuate Whitepapers 
Moblin 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PHP

Making Usage Statistics in PHP
By: Adam Szanto
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 108
    2004-02-16

    Table of Contents:
  • Making Usage Statistics in PHP
  • Save the HTML Title
  • Showing the Statistics Table
  • Showing Figures Based on the Statistics
  • Creating the Image Library
  • Charting the Results
  • Before Saying Goodbye

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

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

     

    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.

     

    PHP ARTICLES

    - 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
    - PHP Frontend to ImageMagick
    - Using PEAR's mimeDecode Module
    - Incoming Mail and PHP







    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway