## LiveStats SQL Table Layout ##
CREATE TABLE webstats (
id int(11) NOT NULL auto_increment,
browser varchar(255) NOT NULL default '',
ip varchar(15) NOT NULL default '',
received date NOT NULL default '0000-00-00',
PRIMARY KEY (id)
) TYPE=MyISAM;
## this is the index.php file ##
<? // header file include ("../livestats/templates/header.inc");
// server connection include ("../livestats/sql/connect.inc");
// getting server info
echo "<table border=0 width=100 cellpadding=6 cellspacing=5><tr valign=top><td colspan=2>";
include ("../livestats/sql/last.stats");
echo "</td></tr><tr valign=top><td>";
// browser.stats include ("../livestats/sql/browser.stats");
echo "</td><td>";
// server.stats include ("../livestats/sql/server.stats");
echo "</td></tr></table>";
// footer file include ("../livestats/templates/footer.inc");
include ("../livestats/livestats_counter.php"); ?>
## if your following this example exactly, create a directory called livestats/ ##
## livestats/livestats_counter.php ##
## also create a folder in livestats called sql and templates
<? // include ("sql/connect.inc.php");
// getting info from user for stats $ip = $REMOTE_ADDR ; $browser = $HTTP_USER_AGENT ;
// inserting into sql $sql = "INSERT INTO $table(ip,browser,received) VALUES ('$ip','$browser',now())"; $results = mysql_query($sql, $connect);
?>
## this is connect.inc.php ##
<?
$server = "localhost"; // place your server name here (eg. yourdomain.com) $login = "yourloginname"; // place your login name here $password = "yourpassword"; // place your password here $db_name = "yourdatabase"; // the database name $table = "webstats"; // your table name (set to webstats, on db.sql)
$connect = mysql_connect($server, $login, $password) or die("couldnt connect"); mysql_select_db($db_name);
## browser : ie ## $sql = "SELECT * FROM $table WHERE browser LIKE ('%MSIE%')"; $result = mysql_query ($sql); $windows = mysql_num_rows($result);
## browser : netscape ## $sql = "SELECT * FROM $table WHERE browser LIKE ('%Netscape%')"; $result = mysql_query ($sql); $netscape = mysql_num_rows ($result);
$query = mysql_query("SELECT * FROM $table WHERE browser LIKE ('%Nav%')"); $navigator = mysql_num_rows($query);
$nav = ($navigator + $netscape);
## browser : linux ## $sql = "SELECT * FROM $table WHERE browser LIKE ('%linux%')"; $result = mysql_query($sql); $linux = mysql_num_rows($result);
## browser : total ## $result = mysql_query("SELECT * FROM $table"); $total = mysql_num_rows($result);
$other_hits = ($linux + $nav + $windows); $other = ($total - $other_hits);
/////////////////////////////////////////////////////////////////////
## os : windows ## $result = mysql_query("SELECT * FROM $table WHERE browser LIKE '%win%'"); $os_windows = mysql_num_rows($result);
## os : macintosh ## $result = mysql_query("SELECT * FROM $table WHERE browser LIKE '%mac%'"); $os_mac = mysql_num_rows($result);
## os : linux ## $result = mysql_query("SELECT * FROM $table WHERE browser LIKE '%linux%'"); $os_linux = mysql_num_rows($result);
## os : unix ## $result = mysql_query("SELECT * FROM $table WHERE browser LIKE '%unix%'"); $os_unix = mysql_num_rows($result);
## os : total ## $result = mysql_query("SELECT * FROM $table"); $total = mysql_num_rows($result);
////////////////////////////////////////////////////////////////////////
?>
## livestats/sql/browser.stats ##
<table border="0" bgcolor="#333333" cellspacing="0" cellpadding="0" width="200">
<tr>
<td bgcolor="#cccccc"><center><b>Browser Statistics</b></center></td>
</tr>
<tr>
<td bgcolor="#eeeeee">
<table width="75%" align="center">
<tr>
<td align="left">
Windows Hits : </td>
<td align="right">
<b><? echo $windows; ?></b></td>
</tr>
<tr>
<td align="left">
Netscape Hits :</td>
<td align="right">
<b><? echo $nav; ?></b></td>
</tr>
<tr>
<td align="left">
Linux Hits : </td>
<td align="right">
<b><? echo $linux; ?></b></td>
</tr>
<tr>
<td align="left">
Other Hits : </td>
<td align="right">
<b><? echo $other; ?></b></td>
</tr>
<tr>
<td align="left">
Total Hits : </td>
<td align="right">
<b><? echo $total; ?></b></td>
</tr>
</table>
</td>
</tr>
</table>
## livestats/sql/last.stats ##
<table border="0" bgcolor="#333333" cellspacing="0" cellpadding="0" width="420">
<tr>
<td bgcolor="#cccccc"><center><b>Top Visitors </b></center></td>
</tr>
<tr>
<td bgcolor="#eeeeee">
<table width="80%" align="center">
<?
## top visitors ## $result = mysql_query("SELECT COUNT(ip) AS info,ip FROM $table GROUP BY ip ORDER by info DESC LIMIT 10");
while ($list = mysql_fetch_array($result)) {
echo "<tr><td align="left">";
echo $list["ip"];
echo "</td><td align="right">";
echo $list["info"];
echo "</td></tr>";
} ?> </table>
</td>
</tr>
</table><br>
## livestats/sql/server.stats ##
<table border="0" bgcolor="#333333" cellspacing="0" cellpadding="0" width="200">
<tr>
<td bgcolor="#cccccc"><center><b>OS Statistics</b></center></td>
</tr>
<tr>
<td bgcolor="#eeeeee">
<table width="75%" align="center">
<tr>
<td align="left">
Windows : </td>
<td align="right">
<b><? echo $os_windows; ?></b></td>
</tr>
<tr>
<td align="left">
Macintosh Hits : </td>
<td align="right">
<b><? echo $os_mac; ?></b></td>
</tr>
<tr>
<td align="left">
Linux Hits : </td>
<td align="right">
<b><? echo $os_linux; ?></b></td>
</tr>
<tr>
<td align="left">
Unix Hits : </td>
<td align="right">
<b><? echo $os_unix; ?></b></td>
</tr>
<tr>
<td align="left">
Total Hits : </td>
<td align="right">
<b><? echo $total; ?></b></td>
</tr>
</table>
</td>
</tr>
</table>
## livestats/inc/header.inc ##
<html>
<body>
your header information here
## livestats/inc/footer.inc ##
my footer ends
</body>
</html>
Run <? include ('livestats/livestats_counter.php'); ?> in the webpages you wanted counted, and your all set.
|
|