$dbhost = '******'; $dbuser = '*****'; $dbpass = '********'; $dbname = '********'; $dbstat = 'stats';TABLE $dbpath = 'path';TABLE $dbctry = 'ctry';TABLE $dbconf = 'cfg';TABLE $version = '2.0.1';
Now the script has an admin page which only admins can see once logged in named summary.php which shows all user info such as
Todays Hits:
Total Hits:
Todays Unique:
Total Unique:
The page is located here stats/summary.php and looks like this
<?php
$timeparts = explode(' ', microtime()); $starttime = $timeparts[1].substr($timeparts[0],1);
require 'secure.php';
require 'confdata.php';
require 'resourceb.php';
$link = mysql_connect($dbhost, $dbuser, $dbpass);
require 'calendar_data.php'; // generates necessary data for clickable calendar
// get date of first visit
$result = mysql_db_query($dbname, "SELECT tstamp FROM $dbstat ORDER BY tstamp ASC LIMIT 1", $link);
$firstVisit = mysql_fetch_array($result);
// today's total visits
$result = mysql_db_query($dbname, "SELECT COUNT(*) FROM $dbstat WHERE dstamp='$dstamp'", $link);
$result = mysql_fetch_array($result);
$dayVisits = $result[0];
// today's unique visitors
$result = mysql_db_query($dbname, "SELECT COUNT(DISTINCT ip) FROM $dbstat WHERE dstamp='$dstamp'", $link);
$result = mysql_fetch_array($result);
$dayUnique = $result[0];
if($dayVisits) { $dayPercent = '(' . round(($dayUnique / $dayVisits) * 100) . '%)'; }
// 30 day average (visits per day)
$tstamp = mktime(0, 0 ,0, $calMonth, $calDay-31, $calYear);
$daysago = date('Ymd', $tstamp);
$result = mysql_db_query($dbname, "SELECT COUNT(*) FROM $dbstat WHERE dstamp>'$daysago' AND dstamp<'$dstamp'", $link);
$result = mysql_fetch_array($result);
$dayAverage = round($result[0]/30);
// top referrer for the day
$result = mysql_db_query($dbname, "SELECT refhost FROM $dbstat WHERE dstamp='$dstamp' AND refhost != ''", $link);
$dayRef = topValue($result, 'refhost');
// top search engine for the day
$result = mysql_db_query($dbname, "SELECT engine FROM $dbstat WHERE dstamp='$dstamp' AND engine != ''", $link);
$dayEngine = topValue($result, 'engine');
// top entry page for the day
$result = mysql_db_query($dbname, "SELECT entry FROM $dbstat WHERE dstamp='$dstamp' AND entry != ''", $link);
$dayEntry = topValue($result, 'entry');
// total number of visits
$result = mysql_db_query($dbname, "SELECT COUNT(*) FROM $dbstat", $link);
$result = mysql_fetch_array($result);
$totalVisits = $result[0];
// total unique visitors
$result = mysql_db_query($dbname, "SELECT COUNT(DISTINCT ip) FROM $dbstat", $link);
$result = mysql_fetch_array($result);
$totalUnique = $result[0];
if($totalVisits) { $totalPercent = '(' . round(($totalUnique / $totalVisits) * 100) . '%)'; }
// average visits per day
$result = mysql_db_query($dbname, "SELECT COUNT(*) FROM $dbstat", $link);
$result = mysql_fetch_array($result);
$result2 = mysql_db_query($dbname, "SELECT COUNT(DISTINCT dstamp) FROM $dbstat", $link);
$result2 = mysql_fetch_array($result2);
$totalAverage = round($result[0] / $result2[0]);
// top referrer total
$result = mysql_db_query($dbname, "SELECT refhost FROM $dbstat WHERE refhost != ''", $link);
$totalRef = topValue($result, 'refhost');
// top search engine total
$result = mysql_db_query($dbname, "SELECT engine FROM $dbstat WHERE engine != ''", $link);
$totalEngine = topValue($result, 'engine');
// top entry page total
$result = mysql_db_query($dbname, "SELECT entry FROM $dbstat WHERE entry != ''", $link);
$totalEntry = topValue($result, 'entry');
// last 10 visitors
$lastTen = array();
$result = mysql_db_query($dbname, "SELECT id,tstamp,ip,host,refhost,browser,os,entry FROM $dbstat WHERE dstamp<='$dstamp' ORDER BY tstamp DESC LIMIT 10", $link);
while($row = mysql_fetch_array($result)) {
$row[tstamp] = date("m/d/Y h:i a", $row[tstamp]);
$row[entry] = pathinfo($row[entry]);
$row[entry] = $row[entry]['basename'];
array_push($lastTen, $row);
}
// hourly traffic summary
$result = mysql_db_query($dbname, "SELECT hstamp FROM $dbstat WHERE dstamp='$dstamp'", $link);
$hours = array();
while($row = mysql_fetch_array($result)) {
array_push($hours, $row[hstamp]);
}
$hours = array_count_values($hours);
array_values($hours);
$topHour = 0;
foreach($hours as $count) {
if($count > $topHour) { $topHour = $count; }
}
mysql_close($link);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>TrackPro <?php echo $version; ?> - Statistics Summary</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
<style type="text/css">
@import url(styles/styles.css);
</style>
</head>
<body>
<div id='container'>
<div id='header'>
<!-- header -->
</div>
<div id='version'>
TrackPro <?php echo $version; ?>
<div id='location'>
Statistics Summary
</div>
<div id='logout'>
<a href='secure.php?logout=true'>Logout</a>
</div>
</div>
<div id='content'>
<div class='moduleSet'>
<div class='moduleSetLeft'>
<div class='moduleSetHeader'>
QuickStats :
<?php
echo substr($dstamp, 4, 2).'/'.substr($dstamp, 6, 2).'/'.substr($dstamp, 0, 4);
if($dstamp == $today) echo ' (Today)';
?>
</div>
<table width='100%' border='0' cellpadding='0' cellspacing='0'>
<tr class='alternate1'>
<td width='130'>
<b>Visits</b>
</td>
<td>
<b><?php echo number_format($dayVisits); ?></b>
</td>
</tr>
<tr class='alternate2'>
<td>
<b>Unique Visits</b>
</td>
<td>
<b><?php echo number_format($dayUnique).' '.$dayPercent; ?></b>
</td>
</tr>
<tr class='alternate1'>
<td>
30 Day Average
</td>
<td>
<?php echo number_format($dayAverage); ?> (Visits per day)
</td>
</tr>
<tr class='alternate2'>
<td>
Top Referrer
</td>
<td>
<?php echo "$dayRef[0] (".number_format($dayRef[1]).")"; ?>
</td>
</tr>
<tr class='alternate1'>
<td>
Top Search Engine
</td>
<td>
<?php echo "$dayEngine[0] (".number_format($dayEngine[1]).")"; ?>
</td>
</tr>
<tr class='alternate2'>
<td>
Top Entry Page
</td>
<td>
<?php echo "$dayEntry[0] (".number_format($dayEntry[1]).")"; ?>
</td>
</tr>
</table>
</div>
<div class='moduleSetRight'>
<div class='moduleSetHeader'>
QuickStats : Since
<?php echo date('m/d/Y', $firstVisit[0]); ?>
</div>
<table width='100%' border='0' cellpadding='0' cellspacing='0'>
<tr class='alternate1'>
<td width='130'>
<b>Visits</b>
</td>
<td>
<b><?php echo number_format($totalVisits); ?></b>
</td>
</tr>
<tr class='alternate2'>
<td>
<b>Unique Visits</b>
</td>
<td>
<b><?php echo number_format($totalUnique).' '.$totalPercent; ?></b>
</td>
</tr>
<tr class='alternate1'>
<td>
Average
</td>
<td>
<?php echo number_format($totalAverage); ?> (Visits
per day)
</td>
</tr>
<tr class='alternate2'>
<td>
Top Referrer
</td>
<td>
<?php echo "$totalRef[0] (".number_format($totalRef[1]).")"; ?>
</td>
</tr>
<tr class='alternate1'>
<td>
Top Search Engine
</td>
<td>
<?php echo "$totalEngine[0] (".number_format($totalEngine[1]).")"; ?>
</td>
</tr>
<tr class='alternate2'>
<td>
Top Entry Page
</td>
<td>
<?php echo "$totalEntry[0] (".number_format($totalEntry[1]).")"; ?>
</td>
</tr>
</table>
</div>
</div>
<br/>
<div class='module'>
<div class='moduleHeader'>
Last 10 Visitors [
<a class='modLink' href='details.php?mode=list&limit=<?php echo "$dayVisits&dstamp=$dstamp"; ?>'>Today</a> :
<a class='modLink' href='details.php?mode=list&limit=all'>List All</a> ]
</div>
<table width='658' cellpadding='0' cellspacing='0'>
<tr class='labels'>
<td width='130' align='center'>
<b>Date / Time</b>
</td>
<td width='105' align='center'>
<b>IP</b>
</td>
<td width='50' align='center'>
<b>System</b>
</td>
<td>
<b>Referrer</b>
</td>
<td>
<b>Entry Page</b>
</td>
<td width='30' align='center'>
<b>Info</b>
</td>
</tr>
<?php $n = 0;
foreach($lastTen as $item) {
$browser = iconBrowser($item[browser]);
$os = iconOS($item[os]);
if(!($n % 2)) $class = 'alternate1'; else $class = 'alternate2';
echo "<tr class='$class'>
<td align='center'>$item[tstamp]</td>
<td align='center'><a href='http://www.whois.sc/$item[ip]' target='_blank'>$item[ip]</a></td>
<td align='center'><img src='$browser' alt='$item[browser]'/><img src='$os' alt='$item[os]'/></td>
<td>$item[refhost]</td>
<td>$item[entry]</td>
<td align='center'><a href='details.php?mode=show&id=$item[id]'><img src='common/info.jpg' alt='Click for details' border='0' hspace='5'/></a></td>
</tr>";
$n++;
}
?>
</table>
</div>
<br/>
<div class='module'>
<div class='moduleHeader'>
Hourly Traffic Summary :
<?php
echo substr($dstamp, 4, 2).'/'.substr($dstamp, 6, 2).'/'.substr($dstamp, 0, 4);
if($dstamp == $today) echo ' (Today)';
?>
</div>
<table width='658' cellpadding='0' cellspacing='0'>
<tr>
<td width='6'>
<!-- SPACER -->
</td>
<?php
for($n = 0; $n < 24; $n++) {
$count = $hours[$n];
if($topHour) $height = $count / $topHour;
$height = round(100 * $height);
echo "
<td width='27' align='center' valign='bottom'>$count<br/><img src='common/pixel_blue.gif' width='22' height='$height' alt=''/></td>
";
}
echo "<td width='6'><!-- SPACER --></td></tr><tr class='labels'><td width='6'><!-- SPACER --></td>";
for($n = 0; $n < 24; $n++) {
if(strlen($n) == 1) $n = '0'.$n;
echo "<td align='center'><b>$n</b></td>";
}
?>
<td width='6'>
<!-- SPACER -->
</td>
</tr>
</table>
</div>
<br/>
</div>
<div id='footer'>
<!-- footer -->
</div>
<div id='menu'>
<div id='calendar'>
<?php require 'calendar_show.php'; ?>
</div>
<?php require 'menu.php'; ?>
</div>
</div>
<?php
$timeparts = explode(' ', microtime()); $endtime = $timeparts[1].substr($timeparts[0],1); $execution = round(($endtime - $starttime), 2);
?>
<div id='credits'>
<?php echo 'Executed in '.$execution.' seconds.'; ?> :
<a href='http://validator.w3.org/check?uri=referer' title='Validate Markup'>xhtml</a> :
<a href='http://jigsaw.w3.org/css-validator/check/referer' title='Validate CSS'>css</a>
</div>
</body>
</html>
Now what i would like to do is show some of this information shown on this page www.domain.com/stats/summary.php on another page lets say www.domain.com/index.php to show my visitors this info ....Todays Hits:
Total Hits:
Todays Unique:
Total Unique:
Now i would greatly appreciate it if someone can tell me how can i do this ?? I am pretty sure that it has something to do with connecting to this stats database and to the specific table to get the value/variables from.... I would greatly appreciate all the help provided
