HomePHP Page 2 - Tracking Website Statistics with PHP
Analyzing the Recorded Data - 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.
From the information collected above, we can divide the data into three main specific information areas:
Website Info: How many visitors, browsers used, and pages visited.
Visitor Info: Pages visited, browsers used, and date of visit.
Page Info : Who visited a particular page, how many times, when and browser used.
To get this information all we have to do is run some very specific SQL queries:
Website Specific Analysis
To count how many people visited the site, run the following code:
$query = "SELECT COUNT(*) FROM stattracker GROUP by ip"; $result=mysql_query($query); $number_of_views = mysql_num_rows($result);
This will count all the different IP addresses in the table. If one person with the same IP address views this site a hundred times, the result of this query will be one; the same thing happens if the person views this site two hundred times.
Number of times a particular browser has been used to visit the site:
$query = "SELECT *,count(*) FROM stattracker GROUP by browser"; $result=mysql_query($query); while ($row =mysql_fetch_array($result)) { echo "browser name = " .$row['browser']. " Used: " .$row ['count (*)']; }
The above query checks how many time a particular browser has been used to visit the site.