Sonderanfertigung für dich ;-)
Die Datei per require_once('statistic.php'); einbinden (am Anfang des Scripts!) und die Box per require('stats.php'); an beliebiger Stelle einfügen.
Benötigte Tabellen:
- stats
- counter
statistic.php
<?php
session_start();
@mysql_connect('host', 'user', 'pass') or die ('Falsche Connection Daten');
@mysql_select_db('database') or die ('Falsche Datenbank');
function site_statistic_get_browser($useragent) {
if (preg_match("=MSIE [0-9]{1,2}.[0-9]{1,2}.*Opera.([0-9]{1})=", $useragent, $browser)) {
return "Opera ".$browser[1]." (als IE)";
} elseif (preg_match("=MSIE ([0-9]{1,2}).[0-9]{1,2}=", $useragent, $browser)) {
return "Internet Explorer ".$browser[1];
} elseif (preg_match("=Opera/([0-9]{1,2}).[0-9]{1,2}=", $useragent, $browser)) {
return "Opera ".$browser[1];
} elseif (preg_match("=Konqueror=", $useragent)) {
return "Konqueror";
} elseif (preg_match("=Netscape/7.[0-9]{1,2}=", $useragent)) {
return "Netscape Navigator 7";
} elseif (preg_match("=^Mozilla.*Firefox\/(.*)$=", $useragent, $browser)) {
return ("Firefox ".$browser[1]);
} elseif (preg_match("=Mozilla/5.[0-9]{1,2}=", $useragent)) {
return "Netscape Navigator 6";
} elseif (preg_match("=Mozilla/([0-9]{1,2}).[0-9]{1,2}=", $useragent, $browser)) {
return "Netscape Navigator ".$browser[1];
} else {
return 0;
}
}
function site_statistic_get_os($useragent){
if (preg_match("=Windows NT 5\.0|Windows 2000=", $useragent)) {
return "Windows 2000";
} elseif (preg_match("=Windows NT 5\.1|Windows XP=", $useragent)) {
return "Windows XP";
} elseif (preg_match("=Windows NT 6\.0|Windows Vista=", $useragent)) {
return "Windows Vista";
} elseif (preg_match("=Windows NT 5\.2|Windows Server 2003|Windows XP x64=", $useragent)) {
return "Windows Server 2003\\Windows XP x64";
} elseif (preg_match("=Windows NT 4\.0|Windows NT|WinNT4\.0=", $useragent)) {
return "Windows NT";
} elseif (preg_match("=Windows 98=", $useragent)) {
return "Windows 98";
} elseif (preg_match("=Windows 95=", $useragent)) {
return "Windows 95";
} elseif (preg_match("=Mac_PowerPC|Macintosh=", $useragent)) {
return "Macintosh";
} elseif (preg_match("=Linux=", $useragent)) {
return "Linux";
} elseif (preg_match("=SunOS=", $useragent)) {
return "SunOS";
} else {
return 0;
}
}
function site_statistic_get_referer ( $referer ) {
if ( ! empty ($referer) ) {
$refzar = parse_url($referer);
$refspa = 'http://'.$refzar['host'].$refzar['path'];
return $refspa;
} else {
return 0;
}
}
if (!array_key_exists('ilchCMSstati',$_SESSION)) {
$_SESSION['ilchCMSstati'] = 'geloggt';
$d = date('j');
$m = date('n');
$y = date('Y');
if ($_SERVER["HTTP_X_FORWARDED_FOR"]) $ip = $_SERVER["HTTP_X_FORWARDED_FOR"];
else $ip = $_SERVER["REMOTE_ADDR"];
$ergResul = mysql_result(mysql_query("SELECT COUNT(ip) FROM stats WHERE ip = '".$ip."' AND `day` = ".$d." AND mon = ".$m." AND yar = ".$y ),0);
if ( $ergResul == 0 ) {
$os = site_statistic_get_os($_SERVER['HTTP_USER_AGENT']);
$br = site_statistic_get_browser($_SERVER['HTTP_USER_AGENT']);
$wt = date('w');
$st = date('G');
$ur = ( isset ($_SERVER['HTTP_REFERER']) ? site_statistic_get_referer($_SERVER['HTTP_REFERER']) : '' );
mysql_query("INSERT INTO stats (wtag,stunde,`day`,mon,yar,os,browser,ip,ref)
VALUES(".$wt.",".$st.",".$d.",".$m.",".$y.",'".$os."','".$br."','".$ip."','".$ur."')");
$dc = ( strlen ($d) == 1 ? '0'.$d : $d );
$mc = ( strlen ($m) == 1 ? '0'.$m : $m );
$cdate = $y.'-'.$mc.'-'.$dc;
$query = "SELECT COUNT(date) FROM `counter` WHERE `date` = '".$cdate."'";
if ( mysql_result(mysql_query($query),0) == 0 ) {
mysql_query('INSERT INTO `counter` (`date`,`count`) VALUES ( "'.$cdate.'" , "1" ) ' );
} else {
mysql_query('UPDATE `counter` SET `count` = `count` +1 WHERE `date` = "'.$cdate.'"');
}
}
}
?>
stats.php
<?php
$heute = date ('Y-m-d');
$ges_visits = @mysql_result(mysql_query("SELECT SUM(count) FROM counter"),0);
$ges_heute = @mysql_result(mysql_query("SELECT count FROM counter WHERE date = '".$heute."'"),0);
$ges_gestern = @mysql_result(mysql_query('SELECT count FROM counter WHERE date < "'.$heute.'" ORDER BY date DESC LIMIT 1'),0);
echo 'Insgesamt: '.$ges_visits.'<br />';
echo 'Heute: '.$ges_heute.'<br />';
echo 'Gestern: '.$ges_gestern;
?>
install.sql (importieren)
CREATE TABLE `counter` (
`date` date NOT NULL,
`count` smallint(5) NOT NULL default '0'
) TYPE=MyISAM;
CREATE TABLE `stats` (
`wtag` tinyint(2) NOT NULL default '0',
`stunde` tinyint(2) NOT NULL default '0',
`day` tinyint(2) NOT NULL default '0',
`mon` tinyint(2) NOT NULL default '0',
`yar` int(4) NOT NULL default '0',
`os` varchar(50) NOT NULL default '',
`browser` varchar(50) NOT NULL default '',
`ip` varchar(20) NOT NULL default '',
`ref` varchar(255) NOT NULL default ''
) TYPE=MyISAM;
Zuletzt modifiziert von Ithron am 09.07.2008 - 18:16:58