/*
Site viewing stats page
*****************************************************
* 2006-07-30 0.1 : intial version
* 2006-11-21 0.2 : by day for current and last month added
* 2006-12-23 0.3 : recent activity added
* 2007-01-06 0.4 : page vistors by day this month updated to work for all years
* 2007-02-28 0.5 : update to deal with single figure dates
* 2007-02-28 0.6 : changed to work from vars section
*****************************************************
*/
include 'include/database.php';
include 'stats_config.php';
function impressions($string,$table)
{
// string = the date to be searched for i.e. 2005-01%
$q = "SELECT * FROM `$table` WHERE `date` LIKE '$string'";
//echo $table;
//echo $q;
$result = mysql_query($q);
$numrows = mysql_numrows($result);
echo (''.$numrows);
}
//****************************************************************************
function vistors($string,$table)
{
// string = the date to be searched for i.e. 2005-01
$q = "SELECT DISTINCT `ip` FROM `$table` WHERE `date` LIKE '$string'";
//echo $table;
$result = mysql_query($q);
$numrows = mysql_numrows($result);
echo (''.$numrows);
}
//****************************************************************************
echo ' Site Usage Statistics : '.$site.'
';
//****************************************************************************
// count total page vistors
$sql = "SELECT COUNT(*) FROM `".$table."` WHERE 1";
$result = mysql_query($sql,$connection);
$myrow = mysql_fetch_row($result);
$visitors = $myrow[0];
//echo "total page vistors : " . $visitors . " ";
//search for safari, MSIE, Firefox, Opera, the rest
$sql = "SELECT COUNT( * ) FROM `".$table."` WHERE `browser_info` LIKE '%MSIE%'";
$result = mysql_query($sql,$connection);
$myrow = mysql_fetch_row($result);
$msie = $myrow[0];
$pmsie = round($msie / $visitors * 100,0);
//echo "total page vistors MSIE : " . $msie . " ";
$sql = "SELECT COUNT( * ) FROM `".$table."` WHERE `browser_info` LIKE '%safari%'";
$result = mysql_query($sql,$connection);
$myrow = mysql_fetch_row($result);
$safari = $myrow[0];
$safari = round($safari / $visitors * 100,0);
//echo "total page vistors safari : " . $safari . " ";
$sql = "SELECT COUNT( * ) FROM `".$table."` WHERE `browser_info` LIKE '%firefox%'";
$result = mysql_query($sql,$connection);
$myrow = mysql_fetch_row($result);
$firefox = $myrow[0];
$pfirefox = round($firefox / $visitors * 100,0);
//echo "total page vistors firefox : " . $firefox . " ";
$sql = "SELECT COUNT( * ) FROM `".$table."` WHERE `browser_info` LIKE '%opera%'";
$result = mysql_query($sql,$connection);
$myrow = mysql_fetch_row($result);
$opera = $myrow[0];
$popera = round($opera / $visitors * 100,0);
//echo "total page vistors opera : " . $opera . " ";
$others = $visitors - $msie - $firefox - $opera - $safari;
$pothers = round($others / $visitors * 100,0);
//************************************************************************
echo'
Total
 |
MSIE
 |
Firefox
 |
Safari
 |
Opera
 |
Others
 |
| '.$visitors.' |
'.$msie.' / '.$pmsie.'% |
'.$firefox.' / '.$pfirefox.'% |
'.$safari.' / '.$psafari.'% |
'.$opera.' / '.$popera.'% |
'.$others.' / '.$pothers.'% |
';
//************************************************************************
$sql = "SELECT * FROM `".$table."` ORDER BY `id` DESC LIMIT 0 , 50";
$result = mysql_query($sql,$connection);
$row_count = 0;
//print title
echo ' Recent Activity
';
//open table
echo "\n";
//create header row
echo "
| Date |
Time |
IP Address |
Page |
\n";
//loop to create contents
while ($myrow = mysql_fetch_row($result)) {
//decide what colour this row is
$row_color = ($row_count % 2) ? $color1 : $color2;
//output row
printf("
| %s |
%s |
%s |
%s |
\n",
$myrow[3],
$myrow[4],
$myrow[2],
$myrow[1]
);
//increment row by 1
$row_count++;
}
//close table
echo " ";
//************************************************************************
$sql = '
SELECT page_name, COUNT( * ) AS poo
FROM '.$table.'
GROUP BY page_name
ORDER BY poo DESC
';
$result = mysql_query($sql,$connection);
$row_count = 0;
//print title
echo ' Page Popularity
';
//open table
echo "\n";
//create header row
echo "
| Page Name |
View Count |
\n";
//loop to create contents
while ($myrow = mysql_fetch_row($result)) {
//decide what colour this row is
$row_color = ($row_count % 2) ? $color1 : $color2;
//output row
printf("
| %s |
%s |
\n",
$myrow[0],
$myrow[1]
);
//increment row by 1
$row_count++;
}
//close table
echo " ";
//*******************************************
//page vistors by day this month
//*******************************************
echo ' Page Vistors by Day this Month
';
echo'
';
//loop to create day cells
$i = 1 ;
while ( $i < 32 ){
echo '| ' . $i .' | ';
$i = $i + 1;
};
echo'
';
//loop to create hit cells
$i = 1 ;
while ( $i < 32 ){
$tempmonth = date (m);
if ($i < 10)
$spacer = "0";
else
$spacer = "";
$tempyear = date (Y);
$tmpdate = $tempyear . "-". $tempmonth . "-" . $spacer . $i;
echo '| '; vistors ($tmpdate,$table); echo ' | ';
$i = $i + 1;
};
echo ' ';
//*******************************************
//page impressions by day this month
//*******************************************
echo ' Page Impressions by Day this Month
';
echo'
';
//loop to create day cells
$i = 1 ;
while ( $i < 32 ){
echo '| ' . $i .' | ';
$i = $i + 1;
};
echo'
';
//loop to create hit cells
$i = 1 ;
while ( $i < 32 ){
$tempmonth = date (m);
if ($i < 10)
$spacer = "0";
else
$spacer = "";
$tempyear = date (Y);
$tmpdate = $tempyear . "-". $tempmonth . "-" . $spacer . $i;
echo '| '; impressions ($tmpdate,$table); echo ' | ';
$i = $i + 1;
};
echo ' ';
//*******************************************
//page vistors by month and year
//*******************************************
echo ' Page Vistors by Year and Month
';
echo'
| |
Jan |
Feb |
Mar |
Apr |
May |
Jun |
Jul |
Aug |
Sept |
Oct |
Nov |
Dec |
| 2005 |
'; vistors ("2005-01%",$table); echo ' |
'; vistors ("2005-02%",$table); echo ' |
'; vistors ("2005-03%",$table); echo ' |
'; vistors ("2005-04%",$table); echo ' |
'; vistors ("2005-05%",$table); echo ' |
'; vistors ("2005-06%",$table); echo ' |
'; vistors ("2005-07%",$table); echo ' |
'; vistors ("2005-08%",$table); echo ' |
'; vistors ("2005-09%",$table); echo ' |
'; vistors ("2005-10%",$table); echo ' |
'; vistors ("2005-11%",$table); echo ' |
'; vistors ("2005-12%",$table); echo '
|
| 2006 |
'; vistors ("2006-01%",$table); echo ' |
'; vistors ("2006-02%",$table); echo ' |
'; vistors ("2006-03%",$table); echo ' |
'; vistors ("2006-04%",$table); echo ' |
'; vistors ("2006-05%",$table); echo ' |
'; vistors ("2006-06%",$table); echo ' |
'; vistors ("2006-07%",$table); echo ' |
'; vistors ("2006-08%",$table); echo ' |
'; vistors ("2006-09%",$table); echo ' |
'; vistors ("2006-10%",$table); echo ' |
'; vistors ("2006-11%",$table); echo ' |
'; vistors ("2006-12%",$table); echo '
|
| 2007 |
'; vistors ("2007-01%",$table); echo ' |
'; vistors ("2007-02%",$table); echo ' |
'; vistors ("2007-03%",$table); echo ' |
'; vistors ("2007-04%",$table); echo ' |
'; vistors ("2007-05%",$table); echo ' |
'; vistors ("2007-06%",$table); echo ' |
'; vistors ("2007-07%",$table); echo ' |
'; vistors ("2007-08%",$table); echo ' |
'; vistors ("2007-09%",$table); echo ' |
'; vistors ("2007-10%",$table); echo ' |
'; vistors ("2007-11%",$table); echo ' |
'; vistors ("2007-12%",$table); echo '
|
| 2008 |
'; vistors ("2008-01%",$table); echo ' |
'; vistors ("2008-02%",$table); echo ' |
'; vistors ("2008-03%",$table); echo ' |
'; vistors ("2008-04%",$table); echo ' |
'; vistors ("2008-05%",$table); echo ' |
'; vistors ("2008-06%",$table); echo ' |
'; vistors ("2008-07%",$table); echo ' |
'; vistors ("2008-08%",$table); echo ' |
'; vistors ("2008-09%",$table); echo ' |
'; vistors ("2008-10%",$table); echo ' |
'; vistors ("2008-11%",$table); echo ' |
'; vistors ("2008-12%",$table); echo '
|
';
//*******************************************
//page vistors by month and year
//*******************************************
echo ' Page Impressions by Year and Month
';
echo'
| |
Jan |
Feb |
Mar |
Apr |
May |
Jun |
Jul |
Aug |
Sept |
Oct |
Nov |
Dec |
| 2005 |
'; impressions ("2005-01%",$table); echo ' |
'; impressions ("2005-02%",$table); echo ' |
'; impressions ("2005-03%",$table); echo ' |
'; impressions ("2005-04%",$table); echo ' |
'; impressions ("2005-05%",$table); echo ' |
'; impressions ("2005-06%",$table); echo ' |
'; impressions ("2005-07%",$table); echo ' |
'; impressions ("2005-08%",$table); echo ' |
'; impressions ("2005-09%",$table); echo ' |
'; impressions ("2005-10%",$table); echo ' |
'; impressions ("2005-11%",$table); echo ' |
'; impressions ("2005-12%",$table); echo '
|
| 2006 |
'; impressions ("2006-01%",$table); echo ' |
'; impressions ("2006-02%",$table); echo ' |
'; impressions ("2006-03%",$table); echo ' |
'; impressions ("2006-04%",$table); echo ' |
'; impressions ("2006-05%",$table); echo ' |
'; impressions ("2006-06%",$table); echo ' |
'; impressions ("2006-07%",$table); echo ' |
'; impressions ("2006-08%",$table); echo ' |
'; impressions ("2006-09%",$table); echo ' |
'; impressions ("2006-10%",$table); echo ' |
'; impressions ("2006-11%",$table); echo ' |
'; impressions ("2006-12%",$table); echo '
|
| 2007 |
'; impressions ("2007-01%",$table); echo ' |
'; impressions ("2007-02%",$table); echo ' |
'; impressions ("2007-03%",$table); echo ' |
'; impressions ("2007-04%",$table); echo ' |
'; impressions ("2007-05%",$table); echo ' |
'; impressions ("2007-06%",$table); echo ' |
'; impressions ("2007-07%",$table); echo ' |
'; impressions ("2007-08%",$table); echo ' |
'; impressions ("2007-09%",$table); echo ' |
'; impressions ("2007-10%",$table); echo ' |
'; impressions ("2007-11%",$table); echo ' |
'; impressions ("2007-12%",$table); echo '
|
| 2008 |
'; impressions ("2008-01%",$table); echo ' |
'; impressions ("2008-02%",$table); echo ' |
'; impressions ("2008-03%",$table); echo ' |
'; impressions ("2008-04%",$table); echo ' |
'; impressions ("2008-05%",$table); echo ' |
'; impressions ("2008-06%",$table); echo ' |
'; impressions ("2008-07%",$table); echo ' |
'; impressions ("2008-08%",$table); echo ' |
'; impressions ("2008-09%",$table); echo ' |
'; impressions ("2008-10%",$table); echo ' |
'; impressions ("2008-11%",$table); echo ' |
'; impressions ("2008-12%",$table); echo '
|
[report ends]
';
?>
|