Troche dużo tego ale sam chciałes
Cytat
<?
// tu ustaw sciezke do statystyki
$istat_path="http://www.yebood.com/muzyka/istats;
error_reporting(E_ERROR|E_PARSE);
$istat["lastip_log"]="$istat_path/logs/lastip.isl";
$istat["stat_log"]="$istat_path/logs/stat.isl";
$istat["browser_log"]="$istat_path/logs/browser.isl";
$istat["os_log"]="$istat_path/logs/os.isl";
$istat["host_log"]="$istat_path/logs/host.isl";
$istat["referer_log"]="$istat_path/logs/referer.isl";
$istat["last_log"]="$istat_path/logs/last.isl";
$istat["lang_log"]="$istat_path/logs/lang.isl";
$istat["keyword_log"]="$istat_path/logs/keyword.isl";
$istat["search_log"]="$istat_path/logs/search.isl";
$istat["domena_log"]="$istat_path/logs/domena.isl";
$istat["pages_log"]="$istat_path/logs/pages.isl";
include($istat_path."/conf.php");
include($istat_path."/mod/browser.php");
include($istat_path."/mod/os.php");
include($istat_path.'/mod/search.php');
//tworzenie plikow
all_create_files();
if(isset($HTTP_X_FORWARDED_FOR) && $HTTP_X_FORWARDED_FOR != ''){
$istat["ip"]=$HTTP_X_FORWARDED_FOR;
} else {
$istat["ip"]=$REMOTE_ADDR;
}
if(eregi(',',$istat[ip])) {
$istat["ip"] = eregi_replace(' ','',$istat[ip]);
$ips = explode(',',$istat["ip"]);
$istat["ip_proxy"] = $ips[0];
$istat["ip"] = $ips[1];
}
$istat["host"]=$REMOTE_HOST;
if(strlen($istat[host]) < 4 || $istat[host] == 'unknown') {
$istat["host"]=gethostbyaddr($istat[ip]);
if(strlen($istat[host]) < 4 || $istat[host] == 'unknown') {
$istat["host"]=gethostbyaddr($istat[ip_proxy]);
}
}
if(!file_exists($istat["stat_log"]))
{
$istat_id=fopen($istat["stat_log"],"w");
for($n=0; $n<47; $n++) fputs($istat_id,"0,");
fputs($istat_id,"0");
fclose($istat_id);
chmod($istat["stat_log"],0666);
}
$istat_dat=file($istat["stat_log"]);
$istat_buf=explode(",",$istat_dat[0]);
$istat_buf[46]++; //liczba odsłon
$istat_dat[0]=implode(",",$istat_buf);
$istat_id=fopen($istat["stat_log"],"w");
flock($istat_id,2);
fputs($istat_id,chop($istat_dat[0]));
flock($istat_id,3);
fclose($istat_id);
$istat_pages=0;
$nwip=explode(";",$istat[wyklucz]);
$nw=count($nwip);
for($n=0; $n<$nw; $n++)
{
if($istat[ip]==$nwip[$n]){ $istat_pages=1; break;}
}
if($istat_pages==0){
if($istat["pages"]=="on") include "$istat_path/pages.php";
$istat["czas"]=time();
$istat_fip=file($istat["lastip_log"]);
$istat_reload=1;
$istat_eflag=0;
$istat[expired]=$istat[expired]*60;
for($istat_n=0; $istat_n<count($istat_fip); $istat_n++)
if(eregi($istat["ip"],$istat_fip[$istat_n])) { $istat_eflag=1; break;}
if($istat_eflag==1){
$istat_ips=explode("|",$istat_fip[$istat_n]);
if($istat_ips[1]+$istat["expired"] < $istat["czas"])
{
$istat_fip[$istat_n]=$istat["ip"]."|".$istat["czas"]."n";
$istat_id=fopen($istat["lastip_log"],"w");
flock($istat_id,2);
for($n=0; $n<count($istat_fip); $n++) fputs($istat_id,chop($istat_fip[$n])."n");
flock($istat_id,3);
fclose($istat_id);
$istat_reload=0;
}
}
else{
$istat_id=fopen($istat["lastip_log"],"a");
flock($istat_id,2);
fputs($istat_id,$istat["ip"]."|".$istat["czas"]."n");
flock($istat_id,3);
fclose($istat_id);
$istat_reload=0;
}
if($istat_reload==0) { // zablokowanie przeładowań
$istat["refer"]=$HTTP_REFERER;
if(!$istat["refer"]) $istat["refer"]="-";
$istat["rok"]=date("Y");
$istat["miesiac"]=date("n");
$istat["dzien"]=date("j");
$istat["fday"]=date("z")+1;
$istat["godzina"]=date("G");
$istat["tydzien"]=date("w");
$istat["unknow"]=0;
$istat_dat=file($istat["stat_log"]);
$istat_buf=explode(",",$istat_dat[0]);
$istat_buf[0]++; // ogólna liczba odwiedzin
$istat_buf[13+$istat["godzina"]]++; // najczęsciej w godzinach
$istat_buf[37+$istat["tydzien"]]++; // najczęsciej w dniach tygodnia
$istat_dat[0]=implode(",",$istat_buf);
$istat_id=fopen($istat["stat_log"],"w");
flock($istat_id,2);
fputs($istat_id,chop($istat_dat[0]));
flock($istat_id,3);
fclose($istat_id);
$istat["rok_log"]=$istat_path."/logs/".$istat["rok"];
if(!file_exists($istat["rok_log"]))
{
$istat_id=fopen($istat["rok_log"],"w");
flock($istat_id,2);
fputs($istat_id,date("L")."n");
for($x=0; $x<366; $x++) fputs($istat_id,"0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0n");
flock($istat_id,3);
fclose($istat_id);
chmod("$istat[rok_log]", 0666);
}
// zapisz kolory i rozdzielczosć
?>
<!-- wstawka Imperator Stats -->
<script language='JavaScript'>
var v=navigator.appName;
if(v!='Netscape') var scolor=screen.colorDepth; else var scolor=screen.pixelDepth;
document.write('<img src="http://<? echo $SERVER_NAME ?>/istat/rstat.php?scr='+screen.width+'&colorbit='+scolor+'" width=1 height=1 border=0>');
</script>
<!-- koniec wstawki -->
<?
istat_save($istat["browser_log"],istatBrowser());
istat_save($istat["os_log"],istatOs());
// statystyka z podziałem na daty
if(date("L")==1) {
$nrmonth=array(31,29,31,30,31,30,31,31,30,31,30,30);
} else {
$nrmonth=array(31,28,31,30,31,30,31,31,30,31,30,30);
}
$istat_nday=file($istat["rok_log"]);
$istat_hour_visit=explode(",",$istat_nday[$istat["fday"]]);
settype($istat_hour_visit[$istat["godzina"]],"integer");
$istat_hour_visit[$istat["godzina"]]++; //zwieksz liczbe odwiedzin o odpowiedniej godzinie
$istat_hour_visit[24]=$istat["tydzien"]; //dzien tygodnia
$istat_nday[$istat["fday"]]=implode(",",$istat_hour_visit);
$istat_id=fopen($istat["rok_log"],"w");
flock($istat_id,2);
for($x=0; $x<count($istat_nday); $x++) fputs($istat_id,chop($istat_nday[$x])."n");
flock($istat_id,3);
fclose($istat_id);
// lista wszystkich ip i host
istat_save($istat["host_log"],$istat["host"]);
// lista domen
if($istat["ip"]!=$istat["host"]){
$istat_dane=explode(".",$istat["host"]);
$istat_ile=count($istat_dane);
if(eregi('/',$istat_dane[$istat_ile-1])) { eregi_replace('/','',$istat_dane[$istat_ile-1]); }
$istat["domena"]=$istat_dane[$istat_ile-2].".".$istat_dane[$istat_ile-1];
istat_save($istat["domena_log"],$istat["domena"]);
}
function textwrap($text){
$wrap=81;
$pocz=0;
$len = strlen($text);
if ($len > $wrap) {
$h = '';
$x = 0;
while($pocz<$len) {
$v = substr($text,$pocz,$wrap);
if(ereg(chr(10),$v)) {
while(ereg(chr(10),$v)==1) {
$plc = strpos($v,chr(10))+1;
$h .= substr($text,$pocz,$plc-2).'<BR>';
$pocz = $pocz+$plc;
$v = substr($text,$pocz,$wrap);
}
$h .= substr($text,$pocz,$wrap).'<BR>';
$pocz = $pocz+$wrap;
} else {
$h .= substr($text,$pocz,$wrap).'<BR>';
$pocz = $pocz+$wrap;
}
}
} else {
$h = $text;
}
return $h;
}
//lista państw z których najczę¶ciej była odwiedzana strona
if ($istat["host"]!=$istat["ip"] && $istat["host"]!="localhost")
{
$istat_lang_ip = substr(strrchr($istat["host"], "."), 1);
istat_save($istat["lang_log"],strtolower($istat_lang_ip));
}
// lista słów kluczowych wpisywanych do wyszukiwarek
$istat[search]=istatSearch();
if($istat[search][0]) { istat_save($istat["search_log"],$istat[search][0]); }
if($istat[search][1]) { istat_save($istat["keyword_log"],$istat[search][1]); }
// lista adresów sk±d przybyli go¶cie
if($istat["refer"]!="-")
{
if($istat[search][1])
{
$istat["ref_tmp"]=explode("?",$istat["refer"]);
$istat["refer"]=$istat["ref_tmp"][0];
}
istat_save($istat["referer_log"],textwrap($istat["refer"]));
}
// lista ostatnich odwiedzin
$istat_lines=file($istat["last_log"]);
$istat_num=count($istat_lines); if($istat_num>1000) $istat_num=500;
$istat_id=fopen($istat["last_log"],"w");
fputs($istat_id,date("Y-m-d H:i").",".$istat["host"].",".$istat["refer"].",".istatOs()."/".istatBrowser()."n");
for($n=0; $n<$istat_num; $n++) fputs($istat_id,chop($istat_lines[$n])."n");
fclose($istat_id);
}
}
echo"<a href=http://$SERVER_NAME/istat/index.php><img src="http://$SERVER_NAME/istat/images/nistat.gif" width=80 height=32 border=0 alt='www.iportal.nano.pl'></a>";
function createfile($filename)
{
$id=fopen($filename,"w");
fputs($id,"");
fclose($id);
chmod($filename, 0666);
}
function all_create_files()
{
GLOBAL $istat;
if(!file_exists($istat["keyword_log"])) { createfile($istat["keyword_log"]); }
if(!file_exists($istat["browser_log"])) { createfile($istat["browser_log"]); }
if(!file_exists($istat["os_log"])) { createfile($istat["os_log"]); }
if(!file_exists($istat["host_log"])) { createfile($istat["host_log"]); }
if(!file_exists($istat["referer_log"])) { createfile($istat["referer_log"]); }
if(!file_exists($istat["last_log"])) { createfile($istat["last_log"]); }
if(!file_exists($istat["lang_log"])) { createfile($istat["lang_log"]); }
if(!file_exists($istat["keyword_log"])) { createfile($istat["keyword_log"]); }
if(!file_exists($istat["search_log"])) { createfile($istat["search_log"]); }
if(!file_exists($istat["domena_log"])) { createfile($istat["domena_log"]); }
if(!file_exists($istat["pages_log"])) { createfile($istat["pages_log"]); }
}
function istat_save($filename,$id_name)
{
$flag=1;
$lines=file($filename);
for($n=0; $n<count($lines); $n++)
{
if(ereg($id_name,$lines[$n]))
{
$tmp=explode("|",$lines[$n]);
$tmp[0]++;
$lines[$n]=implode("|",$tmp);
$flag=0;
break;
}
}
if($flag==1)
{
$istat_id=fopen($filename,"a");
flock($istat_id,2);
fputs($istat_id,"1|$id_namen");
}
else{
$istat_id=fopen($filename,"w");
flock($istat_id,2);
for($n=0; $n<count($lines); $n++) fputs($istat_id,chop($lines[$n])."n");
}
flock($istat_id,3);
fclose($istat_id);
return $flag;
}
?>