Location: PHPKode > projects > MyOWNSpace > MyOWNspace_v8.2/www/myownstat.php
<?php
/// WRITE L O G !!
function log_file($logFile , $content , $fileSizeMax) {
// $logFile, fichier de log
// $content, description de l'évenement loggé
// $fileSizeMax, en octets
@chmod($logFile,0777);
if(@filesize($logFile) > $fileSizeMax){
unlink($logFile);
}
$fileHandle = fopen($logFile,"a");
if(!$fileHandle){
echo 'Unable to open ' . $logFile;
return FALSE;
}
$content = date("Y/m/d H:i:s") . " remote user:" . gethostbyaddr($_SERVER['REMOTE_ADDR']) . " " . $_SERVER['REMOTE_ADDR'] . " " . $content . "\r\n";
fputs($fileHandle, $content);
fclose($fileHandle);
return TRUE;

}
///////////////////////////////////////////
 function manage_log($file , $dir , $type , $taillemax) {
/* Paramètres :
* $file : nom di fichier de log
* $dir : repertoire ou sont sauvegarder les fichiers de log
* $type : type de compressiosn : GZ ou BZ2
* $taillemax : taille max du fichier de log
*/

$type = strtoupper($type);

if (file_exists($file) && filesize($file) > $taillemax)
{
if ($type == 'GZ')
{
$open = 'gzopen';
$write = 'gzwrite';
$close = 'gzclose';
$ext = '.gz';
}
else
{
$open = 'bzopen';
$write = 'bzwrite';
$close = 'bzclose';
$ext = '.bz2';
}

if (preg_match("/([^\.]+)(\.[^\.]+)?$/",$file,$n))
$nam = $n[1].date("Ymd");
else
$nam = $file.date("Ymd");

$i=1;
$name = $nam;
if (isset($n[2]))
$name .= $n[2];
$name .= $ext;
while(file_exists($name))
{
$name = $nam."_$i";
if (isset($n[2]))
$name .= $n[2];
$name .= $ext;
$i++;
}

$fr = fopen($file,'r');
$fz = $open($name,'w');
while($str = fread($fr,1024))
$write($fz,$str);
fclose($fr);
$close($fz);
$fp = fopen($file,'w');
}
else
$fp = fopen($file,'a');

return $fp;

}

///////////////////////////////////////////
if($view_page==1) {
///////////////////////////////////////////
if(isset($_GET['go'])&&($_GET['go']!=""))
{
$go=$_GET['go'];
}
else 
if(isset($_POST['go'])&&($_POST['go']!=""))
{
$go=$_POST['go'];
}
else echo "BAD !!";
////trouve le fichier de conf adequat
$conf_file="myownstat/stat.".$go.".php";

/// CALL LOG
if(!log_file($conf_file,'', 1000000)) echo '->MyOWNerror:stat errors..';

//// READ L O G !
/////////////////////////////////////////// 
$hits = count(file ($conf_file));
///////////////////////////////////////////
////MANAGE BIG LOG FILES
manage_log($conf_file , '/myownstat' , 'GZ' , '1000000') ;
}
///////////////////////////////////////////
/// print(LOGS)
if($view_page!=1){
include "login.inc.php";
include "config.php";

if(isset($_GET['go'])&&($_GET['go']!=""))
{
$go=$_GET['go'];
}
else echo "BAD !!";
if( checkauth() && $myspace[$go]['owner']==$rawuser ) { 
////trouve le fichier de conf adequat
$conf_file="myownstat/stat.".$go.".php";
$hits = count(file ($conf_file));
$lines = file ($conf_file);
$row=0;
foreach ($lines as $line_num => $line) {
if($row>0) {$color='#FFFF66'; $row=-1;} else $color='#FFCCCC';
$stats.= '<li style="background:'.$color.'">'.$line . '</li>'."\n";
$row++;
}
}
else
{ $stats='YOU MUST LOG-IN!';}
include "header.php";
loged($myspace[$go]['owner']);
echo "<b>".menu_options($go)."</b>";

echo $menu.'<br><fieldset><H3>MyOWNstats: <span style="color:red;font-size:20px"><b>'.$hits.'</b></span> Hits!</H3>
      <legend>'.$myspace[$go]['titre'].'</legend><ul>';
echo $stats;
echo'</ul></fieldset><br>';
include("myowntip.html");
include "footer.php";
}

?> 
Return current item: MyOWNSpace