HomePHP Page 4 - Tracking Website Statistics with PHP
Building a Page - PHP
If you have a website, especially one that sells products or services, it can be useful to track the visitors to your site. This article explains how to write a program that will do just that.
What this entire code does is display the three main sets of information as we've discussed previously. It is only a very general snapshot of who visited what page when and what browser they used. You even get the total number of times a particular page was visited.
Another area of analysis that I haven't discussed here is breaking the information down by the date of visit. You can for example run a query to find out the number of times a particular person visited in a month or year. There is just so much that you can do with the information that is collected by the script. There is no single best way of getting this information out, because it depends entirely on individual needs.
Create two more PHP pages and call them p1.php and p2.php. Include the 'theCollector.php' page in both of them. In the p1 one, add a link to p2 and in p2 add a link to p1. These two pages are going to be our test pages.
Here's the code for p1.php. Use the exact same code when you create p2.php:
Run p1.php, click on the link to p2.php and then click on the link to p1.php. Repeat this process a couple of times. This will populate the table with some data for us to use later on.
Conclusion
With the information that you get from the collector script, you can extract a lot more information than I did in this article. You can even use PHP's gd to give a graphical view of your web stats. But for most web masters, this should be adequate or act as a base to write more advanced web statistics scripts.