PHP Custom Web Statistics

Keeping logs of who visits your site is useful as it allows you to see how many people are visiting your site, and which pages are the most popular and most frequently visited. Pages which have low visitor numbers can then be changed to make them more appealing. Alternatively, it may turn out that your navigation system isn't working as well as it could be, and you can then change it to make the pages with low numbers of visitors easier to find.

Creating your own system using PHP and MySQL means that you can still have detailed statistics about who visits your site, even if your web host doesn't allow access to the server log files. It also means that you can create your own custom reports to show the data that is of most interest to you, rather than being locked into the standard reports that many web hosts provide.

  • In this first tutorial of the series, we first look at how to obtain information about visitors to your web site such as the users ip address and information about the users browser and operating system from the special PHP $_SERVER array.
  • We then create an include file containing the MySQL database connection parameters which can be added to any page that requires access to a MySQL database. This gives us the advantage that if the MySQL server is changed in the future, then the new connection parameters only need to be changed once in the include file rather than on every page that uses the MySQL database.
  • Then we create another include file that can be easily added to any web page that you want to log, and writes details about the web page visitor to a MySQL database table ready to be analysedata later date.

 

Please note that this article forms part of a chapter in the DMXzone e-book PHP Web Applications for Dreamweaver: Juicy Solutions for the Busy Developer.

 

$2.89
- OR -

Overview

Table of Content:

  • Using PHP Server Variables to retrieve info about your sites visitors
  • Storing the logging information in the Database
  • Step 1 - Creating a MySQL Database to store the Log Data
  • Step 2 - Creating an include file containing the database connection parameters
  • Step 3 - Creating the code to add the log data to the database
  • Using the logdata.php include file to log details of a web page visitor
  • Step 4 - Adding the include file to a Web Page
  • Summary

Gareth Downes-Powell

Gareth Downes-PowellGareth has a range of skills, covering many computer and internet related subjects. He is proficient in many different languages including ASP and PHP, and is responsible for the setup and maintenance of both Windows and Linux servers on a daily basis.


In his daily web development work he uses the complete range of Macromedia software, including Dreamweaver MX, Flash MX, Fireworks MX and Director to build a number of websites and applications. Gareth has a close relationship with Macromedia, and as a member of Team Macromedia Dreamweaver, he has worked closely in the development of Dreamweaver, and was a beta tester for Dreamweaver MX.


On a daily basis he provides support for users in the Macromedia forums, answering questions and providing help on a range of different web related subjects. He has also written a number of free and commercial extensions for Dreamweaver MX, to further extend its capabilities using its native JavaScript API’s or C++.


As a web host, Gareth has worked with a range of different servers and operating systems, with the Linux OS as his personal favourite. Most of his development work is done using a combination of Linux, Apache and MySQL and he has written extensively about setting up this type of system, and also running Apache and MySQL under Windows.

See All Postings From Gareth Downes-Powell >>

Reviews

Be the first to write a review

You must me logged in to write a review.