Statistieken script
Auteur: XenoX - 26 augustus 2004 - 15:02 - Gekeurd door: Dennisvb - Hits: 11841 - Aantal punten: 3.88 (8 stemmen)
Dit script laat een totaal van de statistieken zien en per dag de hits en unieke hits.
Deze tabel heb je nodig:
CREATE TABLE `stats` (
`ip` varchar(20) NOT NULL default '',
`datum` date NOT NULL default '0000-00-00',
`hits` int(10) NOT NULL default '1'
) TYPE=MyISAM;
CREATE TABLE `stats` (
`ip` varchar( 20 ) NOT NULL default '' ,
`datum`
date NOT
NULL default '0000-00-00' , `hits` int( 10 ) NOT NULL default '1'
) TYPE= MyISAM;
Voorbeeld:
Include stats.php in bijvoorbeeld index.php
En zet index.php in de map stats/
De plaatjes kun je hier downloaden:
http://www.xenox-designs.net/other/stats.zip
Code:
config.php:
<?php
$conf['MysqlHost'] = "localhost"; // Mysql host (meestal localhost)
$conf['MysqlUser'] = "root"; // Mysql gebruiker
$conf['MysqlPass'] = ""; // Mysql wachtwoord
$conf['MysqlDb'] = ""; // Mysql database
###########################################
$conf['Titel'] = "you site.com"; // Titel van je site
$conf['Totaal'] = TRUE; // TRUE als hij het totaal moet laten zien en FALSE als dat niet moet
$conf['Limit'] = 30; // Van hoeveel dagen moet hij de statistieken laten zien
?>
<?php
$conf [ 'MysqlHost' ] = "localhost" ; // Mysql host (meestal localhost)
$conf [ 'MysqlUser' ] = "root" ; // Mysql gebruiker
$conf [ 'MysqlPass' ] = "" ; // Mysql wachtwoord
$conf [ 'MysqlDb' ] = "" ; // Mysql database
###########################################
$conf [ 'Titel' ] = "you site.com" ; // Titel van je site
$conf [ 'Totaal' ] = TRUE ; // TRUE als hij het totaal moet laten zien en FALSE als dat niet moet
$conf [ 'Limit' ] = 30 ; // Van hoeveel dagen moet hij de statistieken laten zien
?>
stats.php
<?php
include("config.php");
mysql_connect($conf['MysqlHost'], $conf['MysqlUser'], $conf['MysqlPass']);
mysql_select_db($conf['MysqlDb']);
$query = mysql_query("SELECT * FROM stats WHERE ip = '".$_SERVER['REMOTE_ADDR']."' AND datum = '".date("Y-m-d")."'") or die(mysql_error());
$count = mysql_num_rows($query);
if($count == 0) {
$query = "INSERT INTO stats (ip, datum, hits) VALUES ('".$_SERVER['REMOTE_ADDR']."', '".date("Y-m-d")."', '1')";
} else {
$obj = mysql_fetch_object($query);
$hits = $obj->hits + 1;
$query = "UPDATE stats SET hits = '".$hits."' WHERE ip = '".$_SERVER['REMOTE_ADDR']."' AND datum = '".date("Y-m-d")."'";
}
mysql_query($query) or die(mysql_error());
?>
<?php
include ( "config.php" ) ;
mysql_connect ( $conf [ 'MysqlHost' ] , $conf [ 'MysqlUser' ] , $conf [ 'MysqlPass' ] ) ;
if ( $count == 0 ) {
$query = "INSERT INTO stats (ip, datum, hits) VALUES ('" . $_SERVER [ 'REMOTE_ADDR' ] . "', '" . date ( "Y-m-d" ) . "', '1')" ; } else {
$hits = $obj -> hits + 1 ;
$query = "UPDATE stats SET hits = '" . $hits . "' WHERE ip = '" . $_SERVER [ 'REMOTE_ADDR' ] . "' AND datum = '" . date ( "Y-m-d" ) . "'" ; }
?>
index.php
<?php
ob_start();
error_reporting(E_ALL);
include("config.php");
mysql_connect($conf['MysqlHost'], $conf['MysqlUser'], $conf['MysqlPass']);
mysql_select_db($conf['MysqlDb']);
?>
<html>
<head>
<title>Statistieken :: <?php echo $conf['Titel']; ?></title>
<style>
body, td { font-family: Verdana; font-size: x-small; }
</style>
</head>
<body>
<center>
<?php
if($conf['Totaal']) {
$query = mysql_query("SELECT * FROM stats GROUP BY ip") or die(mysql_error());
$uhits = mysql_num_rows($query);
$hits = mysql_result(mysql_query("SELECT sum(hits) as total FROM stats"), 0, "total");
$query = mysql_query("SELECT * FROM stats GROUP BY datum") or die(mysql_error());
$delen = mysql_num_rows($query);
$total = $uhits + $hits;
$bar1 = round($hits / $total * 100);
$bar2 = round($uhits / $total * 100);
?>
<table border="0" cellpadding="5" cellspacing="0" width="100%" style="border: 1px solid #DDDDDD;">
<tr>
<td colspan="2" style="border-bottom: 1px dashed #DDDDDD;" bgcolor="#EFEFEF"><b>Totaal</b></td>
</tr>
<tr>
<td width="140">Hits: (<?php echo $hits; ?>)</td>
<td><img src="bar_line.gif" width="1" height="15"><img src="bar_1.gif" width="<?php echo $bar1; ?>%" height="15"><img src="bar_line.gif" width="1" height="15"><img src="bar_2.gif" width="<?php echo $bar2 - 1; ?>%" height="15"><img src="bar_line.gif" width="1" height="15"></td>
</tr>
<tr>
<td width="140" bgcolor="#EFEFEF">Unieke hits: (<?php echo $uhits; ?>)</td>
<td bgcolor="#EFEFEF"><img src="bar_line.gif" width="1" height="15"><img src="bar_1.gif" width="<?php echo $bar2; ?>%" height="15"><img src="bar_line.gif" width="1" height="15"><img src="bar_2.gif" width="<?php echo $bar1 - 1; ?>%" height="15"><img src="bar_line.gif" width="1" height="15"></td>
</tr>
</table>
<br>
<?php
}
$select1 = mysql_query("SELECT * FROM stats GROUP BY datum ORDER BY datum DESC LIMIT 0,".$conf['Limit']) or die (mysql_error());
while($get = mysql_fetch_object($select1)) {
$select = mysql_query("SELECT * FROM stats WHERE datum = '".$get->datum."'") or die (mysql_error());
$uhits = mysql_num_rows($select);
$hits = mysql_result(mysql_query("SELECT sum(hits) as total FROM stats WHERE datum = '".$get->datum."'"), 0, "total");
$total = $uhits + $hits;
$bar1 = $hits / $total * 100;
$bar2 = $uhits / $total * 100;
$date = explode("-", $get->datum);
?>
<table border="0" cellpadding="5" cellspacing="0" width="100%" style="border: 1px solid #DDDDDD;">
<tr>
<td colspan="2" style="border-bottom: 1px dashed #DDDDDD;" bgcolor="#EFEFEF"><b><?php echo $date[2]."-".$date[1]."-".$date[0]; ?></b></td>
</tr>
<tr>
<td width="140">Hits: (<?php echo $hits; ?>)</td>
<td><img src="bar_line.gif" width="1" height="15"><img src="bar_1.gif" width="<?php echo $bar1; ?>%" height="15"><img src="bar_line.gif" width="1" height="15"><img src="bar_2.gif" width="<?php echo $bar2 - 1; ?>%" height="15"><img src="bar_line.gif" width="1" height="15"></td>
</tr>
<tr>
<td width="140" bgcolor="#EFEFEF">Unieke hits: (<?php echo $uhits; ?>)</td>
<td bgcolor="#EFEFEF"><img src="bar_line.gif" width="1" height="15"><img src="bar_1.gif" width="<?php echo $bar2; ?>%" height="15"><img src="bar_line.gif" width="1" height="15"><img src="bar_2.gif" width="<?php echo $bar1 - 1; ?>%" height="15"><img src="bar_line.gif" width="1" height="15"></td>
</tr>
</table>
<br>
<?php
}
?>
Statistieken script gemaakt door: XenoX Designs
</center>
</body>
</html>
<?php
include ( "config.php" ) ;
mysql_connect ( $conf [ 'MysqlHost' ] , $conf [ 'MysqlUser' ] , $conf [ 'MysqlPass' ] ) ; ?>
<html>
<head>
<title>Statistieken ::
<?php echo $conf [ 'Titel' ] ; ?> </title>
<style>
body, td { font-family: Verdana; font-size: x-small; }
</style>
</head>
<body>
<center>
<?php
if ( $conf [ 'Totaal' ] ) {
$total = $uhits + $hits ;
$bar1 = round ( $hits / $total * 100 ) ; $bar2 = round ( $uhits / $total * 100 ) ; ?>
<table border="0" cellpadding="5" cellspacing="0" width="100%" style="border: 1px solid #DDDDDD;">
<tr>
<td colspan="2" style="border-bottom: 1px dashed #DDDDDD;" bgcolor="#EFEFEF"><b>Totaal</b></td>
</tr>
<tr>
<td width="140">Hits: (
<?php echo $hits ; ?> )</td>
<td><img src="bar_line.gif" width="1" height="15"><img src="bar_1.gif" width="
<?php echo $bar1 ; ?> %" height="15"><img src="bar_line.gif" width="1" height="15"><img src="bar_2.gif" width="
<?php echo $bar2 - 1 ; ?> %" height="15"><img src="bar_line.gif" width="1" height="15"></td>
</tr>
<tr>
<td width="140" bgcolor="#EFEFEF">Unieke hits: (
<?php echo $uhits ; ?> )</td>
<td bgcolor="#EFEFEF"><img src="bar_line.gif" width="1" height="15"><img src="bar_1.gif" width="
<?php echo $bar2 ; ?> %" height="15"><img src="bar_line.gif" width="1" height="15"><img src="bar_2.gif" width="
<?php echo $bar1 - 1 ; ?> %" height="15"><img src="bar_line.gif" width="1" height="15"></td>
</tr>
</table>
<br>
<?php
}
$select1 = mysql_query ( "SELECT * FROM stats GROUP BY datum ORDER BY datum DESC LIMIT 0," . $conf [ 'Limit' ] ) or
die ( mysql_error ( ) ) ;
$hits = mysql_result ( mysql_query ( "SELECT sum(hits) as total FROM stats WHERE datum = '" . $get -> datum . "'" ) , 0 , "total" ) ;
$total = $uhits + $hits ;
$bar1 = $hits / $total * 100 ;
$bar2 = $uhits / $total * 100 ;
?>
<table border="0" cellpadding="5" cellspacing="0" width="100%" style="border: 1px solid #DDDDDD;">
<tr>
<td colspan="2" style="border-bottom: 1px dashed #DDDDDD;" bgcolor="#EFEFEF"><b>
<?php echo $date [ 2 ] . "-" . $date [ 1 ] . "-" . $date [ 0 ] ; ?> </b></td>
</tr>
<tr>
<td width="140">Hits: (
<?php echo $hits ; ?> )</td>
<td><img src="bar_line.gif" width="1" height="15"><img src="bar_1.gif" width="
<?php echo $bar1 ; ?> %" height="15"><img src="bar_line.gif" width="1" height="15"><img src="bar_2.gif" width="
<?php echo $bar2 - 1 ; ?> %" height="15"><img src="bar_line.gif" width="1" height="15"></td>
</tr>
<tr>
<td width="140" bgcolor="#EFEFEF">Unieke hits: (
<?php echo $uhits ; ?> )</td>
<td bgcolor="#EFEFEF"><img src="bar_line.gif" width="1" height="15"><img src="bar_1.gif" width="
<?php echo $bar2 ; ?> %" height="15"><img src="bar_line.gif" width="1" height="15"><img src="bar_2.gif" width="
<?php echo $bar1 - 1 ; ?> %" height="15"><img src="bar_line.gif" width="1" height="15"></td>
</tr>
</table>
<br>
<?php
}
?>
Statistieken script gemaakt door: XenoX Designs
</center>
</body>
</html>
Download code (.txt)
Stemmen
Niet ingelogd.