Location: PHPKode > projects > Inspirado > plugins/statistics/page_View-Stats.php
<?php

if (!function_exists("doNothing"))
	die("Hacking attempt!");

print "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
	<tr valign=\"top\">
    <td>";

//last 10 days visits/hits
$i=1;
$day=0;
print "<table border=\"0\" cellspacing=\"20\" cellpadding=\"0\">
	<tr>
    <td><b>Day</b></td>
    <td><b>Visits</b></td>
    <td><b>Hits</b></td>
  </tr>";

while ($i) {
	
	$visits=0;
	$iparray=array();
	$dif=0;
	
	$stats = dbQuery("SELECT * FROM ".DBPREFIX."plugin_statistics WHERE YEAR(visitdate)=".date("Y",strtotime($day." day"))." AND MONTH(visitdate)=".date("m",strtotime($day." day"))." AND DAY(visitdate)=".date("d",strtotime($day." day"))."");
	
	$hits = mysql_num_rows($stats);
	
	while ($ip=mysql_fetch_array($stats,MYSQL_ASSOC)) {
		
		$iparray[] = $ip["ipaddress"];
		
	}
	
	$visits = count(array_unique($iparray));
	
	print "<tr>
    <td>".date("d M",strtotime($day." day"))."</td>
    <td>".$visits."</td>
    <td>".$hits."</td>
  </tr>";
  
	$day--;
	if ($day==-10) {
		$i=0;
	}
	
}

print "</table>";

print "</td>
    <td>";

//listed by platform
print "<table border=\"0\" cellspacing=\"20\" cellpadding=\"0\">
	<tr>
    <td><b>Platform</b></td>
    <td><b>Visits</b></td>
    <td><b>Hits</b></td>
  </tr>";

$opsys = array("Linux","Windows","Macintosh");
$visitsarray = array();

foreach ($opsys as $os) {
	$ops = dbQuery("SELECT * FROM ".DBPREFIX."plugin_statistics WHERE operatingsystem='".$os."'");
	if (mysql_num_rows($ops)) {
		$ops1 = mysql_fetch_array($ops);
		while ($visits=mysql_fetch_array($ops,MYSQL_ASSOC)) {
			$visitsarray[] = $visits["ipaddress"];
		}
		$visits = count(array_unique($visitsarray));
		print "<tr>
    <td>".$ops1["operatingsystem"]."</td>
    <td>".$visits."</td>
    <td>".mysql_num_rows($ops)."</td>
  </tr>";
	}
}

print "</table>";

//listed by navigators
print "<table border=\"0\" cellspacing=\"20\" cellpadding=\"0\">
	<tr>
    <td><b>Navigator</b></td>
    <td><b>Visits</b></td>
    <td><b>Hits</b></td>
  </tr>";

$navigator = array("Opera","Firefox","Safari","IExplorer","Flock","Phoenix","Firebird","Camino","Netscape","Chimera","Konqueror","Lynx","Links");
$visitarray = array();

foreach ($navigator as $nav) {
	$navs = dbQuery("SELECT * FROM ".DBPREFIX."plugin_statistics WHERE navigator='".$nav."'");
	if (mysql_num_rows($navs)) {
		$navs1 = mysql_fetch_array($navs);
		while ($visits=mysql_fetch_array($navs,MYSQL_ASSOC)) {
			$visitsarray[] = $visits["ipaddress"];
		}
		$visits = count(array_unique($visitsarray));
		print "<tr>
    <td>".$navs1["navigator"]."</td>
    <td>".$visits."</td>
    <td>".mysql_num_rows($navs)."</td>
  </tr>";
	}
}

print "</table>";

print "</td>
    <td>";

//general stats
print "<table border=\"0\" cellspacing=\"20\" cellpadding=\"0\">
	<tr>
    <td><b>Stats</b></td>
    <td><b>Visits</b></td>
    <td><b>Hits</b></td>
  </tr>";
$visitarray = array();

$total = dbQuery("SELECT * FROM ".DBPREFIX."plugin_statistics");
$total_hits = mysql_num_rows($total);
while ($visit=mysql_fetch_array($total,MYSQL_ASSOC)) {
	$visitarray[] = $visit["ipaddress"];
}
$total_visits = count(array_unique($visitarray));

print "<tr>
    <td>Total</td>
    <td>".$total_visits."</td>
    <td>".$total_hits."</td>
  </tr>";

print "</table>";
print "</table>";

print "<table border=\"0\" cellspacing=\"20\" cellpadding=\"0\">
	<tr valign=\"top\">
    <td>";

//last year statistics
$i=1;
$month=0;
print "<table border=\"0\" cellspacing=\"20\" cellpadding=\"0\">
	<tr>
    <td><b>Month</b></td>
    <td><b>Visits</b></td>
    <td><b>Hits</b></td>
  </tr>";

while ($i) {
	
	$visits=0;
	$iparray=array();
	$dif=0;
	
	$stats = dbQuery("SELECT * FROM ".DBPREFIX."plugin_statistics WHERE YEAR(visitdate)=".date("Y",strtotime($month." month"))." AND MONTH(visitdate)=".date("m",strtotime($month." month")));
	
	$hits = mysql_num_rows($stats);
	
	while ($ip=mysql_fetch_array($stats,MYSQL_ASSOC)) {
		
		$iparray[] = $ip["ipaddress"];
		
	}
	
	$visits = count(array_unique($iparray));
	
	print "<tr>
    <td>".date("M Y",strtotime($month." month"))."</td>
    <td>".$visits."</td>
    <td>".$hits."</td>
  </tr>";
  
	$month--;
	if ($month==-12) {
		$i=0;
	}
	
}

print "</table>";

print "</td>
    <td>";
	
//last 20 external referrers
print "<table border=\"0\" cellspacing=\"20\" cellpadding=\"0\">
	<tr>
    <td><b>Date</b></td>
    <td><b>Referrer</b></td>
  </tr>";

$ref = dbQuery("SELECT * FROM ".DBPREFIX."plugin_statistics");
$ref = mysql_fetch_array($ref,MYSQL_ASSOC);

$thisref = $_SERVER["HTTP_REFERER"];
$thisref = split("/",substr($thisref,7,strlen($thisref)-7));
$thisref = "http://".$thisref[0];

$notlike = dbQuery("SELECT * FROM ".DBPREFIX."plugin_statistics WHERE referrer NOT LIKE '%".$thisref."%'");
while ($referrer=mysql_fetch_array($notlike,MYSQL_ASSOC)) {
	if ($referrer["referrer"]!="")
		print "<tr>
    <td>".$referrer["visitdate"]."</td>
    <td><a href=\"".$referrer["referrer"]."\">".$referrer["referrer"]."</a></td>
  </tr>";
}

print "</table>";

print "</td>
  </tr></table>";

?>
Return current item: Inspirado