Jump to content
php.lv forumi

izdabūt no LOG vidējo un maksimālo


radikaalz

Recommended Posts

Sveikiņi!

apmeklējumu skaitītājs.

Netiek izmantota DB, bet dati tiek tureeti txt failos.

 

counter.php

 

 

<?php
ini_set('date.timezone', 'Europe/Riga');
extract($HTTP_GET_VARS);
extract($HTTP_POST_VARS);
$ip = getenv(REMOTE_ADDR);
$date = date("d");
$today = date("d:M:Y");
$user = file("counter.txt");
$lis = 0;
$log_file = "log.txt";
$log_lenght = 30;
$max_file_size = 3;
$file_size= filesize($log_file);
$log_size =	$file_size/1024;
if ($action!="stats"){
$qwe = file("raw.txt");
for($b = 0; $b <sizeof($qwe);$b++){
$last = explode("|",$qwe[$b]);
}
$last1file = fopen ("raw.txt", "w");
fwrite ($last1file, $last[0]+1);
fclose ($last1file);
if ($log_size > $max_file_size) {
$filename = "log.txt"; 
$fd = fopen ($filename, "r"); 
$stuff = fread ($fd, filesize($filename)); 
fclose ($fd);
$last_file = fopen ("temp.txt", "a+");
fwrite ($last_file, $stuff);
fclose($last_file);
$fz = fopen ("log.txt", "w");
fwrite ($fz, "");
fclose($fz);
$filename1 = "temp.txt"; 
$fd1 = fopen ($filename1, "r"); 
$stuff1 = fread ($fd1, filesize($filename1)-1024); 
fclose ($fd1);
$fm = fopen ("log.txt", "a+");
fwrite ($fm, $stuff1);
fclose ($fm);
$fy = fopen ("temp.txt", "w");
fwrite ($fy, "");
fclose($fy);
}
for($x=0;$x<sizeof($user);$x++) {
$temp = explode(";",$user[$x]);
$opp[$x] = "$temp[0];$temp[1];$temp[2];";
$such = strstr($temp[0],$ip.".6978521");
if($such) {
$list[$lis] = $opp[$x];
$lis++; 
}
if($temp[1] != $date) {
$fp = fopen ("log.txt", "a+");
$fw = fwrite ($fp, sizeof($user));
$fw = fwrite ($fp, ";");
$fw = fwrite ($fp, $temp[2]);
$fw = fwrite ($fp, ";");
$fw = fwrite ($fp, "$last[0]");
$fw = fwrite ($fp, ";");
$fw = fwrite ($fp, "\n");
fclose ($fp);
$last2file = fopen ("raw.txt", "w");
$mm =  fwrite ($last2file, "1");
fclose ($last2file);
$fq = fopen ("counter.txt", "w");
$fy = fwrite ($fq, $ip);
$fy = fwrite ($fq, ".6978521");
$fy = fwrite ($fq, ";");
$fy = fwrite ($fq, $date);
$fy = fwrite ($fq, ";");
$fy = fwrite ($fq, $today);
$fy = fwrite ($fq, ";");
$fy = fwrite ($fq, "\n");
fclose ($fq);
break;	   
}
}
if(sizeof($list) != "0") {
}else{
$fp = fopen ("counter.txt", "a+");
$fw = fwrite ($fp, $ip);
$fw = fwrite ($fp, ".6978521");
$fw = fwrite ($fp, ";");
$fw = fwrite ($fp, $date);
$fw = fwrite ($fp, ";");
$fw = fwrite ($fp, $today);
$fw = fwrite ($fp, ";");
$fw = fwrite ($fp, "\n");
fclose ($fp);
}
}
if($action == "stats"){
$db_file = "log.txt";
$latest_max = 30;
$lines = file($db_file);
$a = count($lines)-1;
$u = $a - $latest_max;
$unique = file("counter.txt");
$ut = count($unique);
$file_size= filesize("log.txt");
$log_size =	$file_size/1024;
$raw = "raw.txt"; 
$fn = fopen ($raw, "r"); 
$puff = fread ($fn, filesize($raw)); 
fclose ($fn);
echo "<font face=arial size=2>Šodienas unikālie apmeklējumi: <B>$ut</B><BR> Šodien atkārtotie apmeklējumi: <B>$puff </B></font><HR color=#CCCCCC>";
?>

<STYLE type=text/css>
TD {
COLOR: #000000; FONT-FAMILY: Verdana, Helvetica, Arial; FONT-SIZE: 13px
}
</STYLE>
<font face=arial size=2><U><B>Statistika par pēdējām 30 dienām </B></U><table border=1 cellspacing=0 bordercolor=#00000 width=50% bgcolor=#AFC6DB><td border=1 width=15%><B>Diena</B></td><td width=15%  border=1><B>Unikālie apmeklējumi</B></td><td border=1 width=15%><B>Atkārtotie apmeklējumi</B></td>
<?php
for($i = $a; $i >= $u ;$i--){
$temp = explode(";",$lines[$i]);
echo "<tr><td border=1 width=15%>$temp[1]</td><td width=15% border=1>$temp[0]</td><td width=15% border=1>$temp[2]</td>";
}
?>
</table></font>
<?php
}
?> 

 

 

 

tāds izskatās

log.txt

3;10:Jan:2010;3;
39;11:Jan:2010;98;
56;12:Jan:2010;209;
157;13:Jan:2010;357;
58;14:Jan:2010;295;

 

skaidrojums (par piemēru otrā rindiņa no augšas)

39 (unikālie apmeklējumi);11:Jan:2010;98( atkārtotie apmeklējumi);

 

 

Vajadzīga būs statistikas tabula

Nu lūk, kāds var pateikt, kā lai es dabūju ārā vidējo no visām dienām, jo dienas skaitās visu laiku un kā dabūt lielāko apmeklējumu un kurā dienā?

 

Vēlamais outputs būtu:

 

average: 150

Max in a day(record): 520

 

 

Paldies

Edited by radikaalz
Link to comment
Share on other sites

radikaalz, lūdzdu neapvainojies, bet saproti, lasīt to kodu bija nenormāli grūti(laikam tāpēc arī neizlasiju).

Neņem ļaunā, esmu pasvinējis šovakar.

average vēl nav īsti skaidrs kam, bet max records in a day jau ir count(file("fails_kur_ir_ieraksti.txt")), ja vien in a day nav visu laiku vienā failā rakstīts.

Link to comment
Share on other sites

radikaalz, lūdzdu neapvainojies, bet saproti, lasīt to kodu bija nenormāli grūti(laikam tāpēc arī neizlasiju).

Neņem ļaunā, esmu pasvinējis šovakar.

average vēl nav īsti skaidrs kam, bet max records in a day jau ir count(file("fails_kur_ir_ieraksti.txt")), ja vien in a day nav visu laiku vienā failā rakstīts.

 

Piedod par pulēm, bet kodu iedeva citā forumā. paldies puiši!

SOLVED

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...