Скрипт парсирует файл лога веб сервера apache, пропускает ненужные записи и отображаем в читабельном виде.
Что именно пропускать задается в массиве $aSkip
<?
$aLines = file('1.log');
$aSkip = array();
$aSkip[] = 'option=com_gost&task=save HTTP';
$aSkip[] = 'option=com_gost&Itemid=32&mosmsg=%C2%FB%2B%E2%E2%E5%EB%E8%2B%ED%E5%E2%E5%F0%ED%FB%E9%2B%EA%EE%E4 HTTP';
$aSkip[] = 'option=com_gost&Itemid=32&mosmsg=%C2%FB+%E2%E2%E5%EB%E8+%ED%E5%E2%E5%F0%ED%FB%E9+%EA%EE%E4 HTTP';
$aSkip[] = 'option=com_gost& HTTP';
$aSkip[] = 'option=com_gost&Itemid=32';
$aSkip[] = '.xml HTTP';
$aSkip[] = '.gif HTTP';
$aSkip[] = '.jpg HTTP';
$aSkip[] = '.gif HTTP';
$aSkip[] = '.txt HTTP';
$aSkip[] = '.css HTTP';
$aSkip[] = '.js HTTP';
$aSkip[] = '.png HTTP';
$aSkip[] = '.ico HTTP';
$aSkip[] = 'HEAD / HTTP';
$aSkip[] = 'GET / HTTP';
$aSkip[] = 'scriptaculous.js?load=effects,builder HTTP';
$aSkip[] = 'option=com_sorooms&Itemid=28 HTTP';
$aSkip[] = 'option=com_content&task=view&id=6&Itemid=10 HTTP';
$aSkip[] = 'option=com_flippingbook&Itemid=40&book_id=4 HTTP';
$aSkip[] = 'option=com_content&task=view&id=3&Itemid=3 HTTP';
function Skiper($sUrl)
{
global $aSkip;
$bRet = True;
foreach($aSkip as $sSkip)
{
if (strpos($sUrl, $sSkip) !== False)
{
$bRet = False;
}
}
return $bRet;
}
function parseLine($sText)
{
$sPattern = "|";
$sPattern .= '';
$sPattern .= '(.*?) '; # 1 - ip
$sPattern .= '(.*?) - '; # 2 - host
$sPattern .= '\[(.*?)\] '; # 3 - Date
$sPattern .= '"(.*?)" '; # 4 - URL
$sPattern .= '(.*?) '; # 5 - X3
$sPattern .= '(.*?) '; # 6 - X3 2
$sPattern .= '"(.*?)" '; # 7 - URL 2
$sPattern .= '"(.*?)"'; # 8 - User Agent
$sPattern .= '';
$sPattern .= "|si";
preg_match_all($sPattern, $sText, $aMatches, PREG_SET_ORDER);
/*
echo '<pre>';
print_r($aMatches);
echo '</pre>';
die();
//*/
return $aMatches;
}
ob_start();
$i=0;
$j=0;
foreach ($aLines as $line)
{
$aMatches = parseLine($line);
if (Skiper($aMatches[0][4]))
{
echo '#: '.$i.'<br>';
echo 'URL 1: '.$aMatches[0][4].'<br>';
echo 'URL 2: '.$aMatches[0][7].'<br>';
echo '<hr>';
$j++;
}
$i++;
}
$sRet = ob_get_clean();
echo '<b>'.$j.'</b><br>'.$sRet;
?>
Скачать