Home arrow PHP arrow Page 3 - Tracking Website Statistics with PHP

Visitor Specific Analysis - 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.

TABLE OF CONTENTS:
  1. Tracking Website Statistics with PHP
  2. Analyzing the Recorded Data
  3. Visitor Specific Analysis
  4. Building a Page
By: Jacques Noah
Rating: starstarstarstarstar / 34
September 12, 2006

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

Number of times user visited:

$query = "SELECT count(*) FROM stattracker WHERE ip =
'127.0.0.1'";
$result=mysql_query($query);
while ($row =mysql_fetch_array($result)) {
echo "Visited " .$row['count(*)']. " times";
}

Here I'm checking how many times a particular user visited the site. In this case the visitor is identified by their IP address.

Pages user visited

$query = "SELECT *,count(*) FROM stattracker WHERE ip =
'127.0.0.1' GROUP BY page";
$result=mysql_query($query);
while ($row =mysql_fetch_array($result)) {
echo "Page: " .$row['page']. "Viewed: ".$row['count(*)']. "<br>";
}

Browser used when visiting

$query = "SELECT *,count(*) FROM stattracker WHERE ip =
'127.0.0.1' GROUP BY browser";
$result=mysql_query($query);
while ($row =mysql_fetch_array($result)) {
echo "Browser used: " .$row['browser']. "Used: ".$row['count
(*)']. "times<br>";
}

Number of visits by this user in last 30 days:

$query = "SELECT *,COUNT(*) FROM stattracker WHERE ip =
'127.0.0.1' AND DATE_SUB(CURDATE(),INTERVAL 30 DAY) GROUP BY
page";
$result=mysql_query($query);
while ($row =mysql_fetch_array($result)) {
echo "Page: " .$row['page']. "Viewd: ".$row['COUNT(*)']. "times<br>";
}

Page Specific Analysis

How many times a particular page has been visited:

$query = "SELECT count(*) FROM stattracker WHERE page =
'/pagename.php'";
$result=mysql_query($query);
while ($row =mysql_fetch_array($result)) {
echo "Visited " .$row['count(*)']. " times";
}

Who visits this page?

$query = "SELECT *,count(*) FROM stattracker WHERE page =
'/pagename.php' GROUP BY ip";
$result=mysql_query($query);
while ($row =mysql_fetch_array($result)) {
echo "Visited " .$row['count(*)']. " times. By: ".$row['ip'];
}



 
 
>>> More PHP Articles          >>> More By Jacques Noah
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PHP ARTICLES

- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: