Home arrow PHP arrow Page 2 - 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 - Save the HTML Title
(Page 2 of 7 )

As I've already mentioned above, it can be useful to save the HTML title of the page. We'll use header.php to show the <title></title> HTML tag. My solution to know the HTML title is to define this PHP constant 'TITLE'. I define it in the index.php, before it includes header.php.

// showing a topic using given data
define('TITLE'"Adam's forum > Topic: $topicname"); 
// here comes the main part 

Now the included header.php can save the TITLE constant.
Here's the query to save the data. Put this piece to the beginning of the header.php.

$q='insert into hits (Host, Site, Title, Date) values
.addslashes($_SERVER['QUERY_STRING']).'", "'.addslashes(TITLE).'", now())';
mysql_query($q) or print(mysql_error());

Details explained above. Note addslashes() that's necessary when writing strings in a database because of the hacking attempts. This is some kind of encoding method, so you'll need to decode it when you write the string out by the stripslashes() function.

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-2019 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials