According to the actual work need, want to find out what you want from the visit log, such as files not found, from Google or from Yahoo or from other places, or search engine spider access. The principle is very simple is to open the file, filter the record, break down the record field, the list of the desired results. Almost by a PHP function Preg_match () done. The following is the source code, study it yourself.
<title>
Simple Tools for website logs
</title>
<body>
<form name= "My_form" method= "POST" >
Select Your type:<br>
<select name= "Type" >
<option value= "" >get the null links</option>
<option value= "Yahoo" >acess from yahoo</option>
<option value= "Google" >access from google</option>
<option value= "MSN" >access from msn</option>
<option value= "Robot" >access by robots</option>
</select>
<input type= "Submit" name= "Submit" value= "Get the result" >
</form>
<table border=1>
<tr bgcolor= "#FFCCFF" >
<td><font color= "#000000" >ClientIP</font></td>
<td><font color= "#000000" >AccessTime</font></td>
<td><font color= "#000000" >TargetPage</font></td>
<td><font color= "#000000" >Code</font></td>
<td><font color= "#000000" >FromURL</font></td>
<td><font color= "#000000" >client env</font></td>
</tr>
? Php
$doc _path= $_server["Document_root"];
if (substr ($doc _path,-1)!= "/") {
$doc _path= $doc _path. " /";
}
if ($type = = ' Yahoo ') {
$lines = File ($doc _path. ' Logs/access_log ');
foreach ($lines as $line _num => $line) {
if (Preg_match ("/yahoo/i", Strtolower ($line)) {
if (!preg_match ("/slurp/", Strtolower ($line)) {
Preg_match ("/[0-9.] +)? ([ -]+)? (/[)? ([0-9a-za-z+://]+)? (/])? (/"Get///)?" ([a-z0-9a-z.///?&=%_/-:+]+)? (HTTP//1. [1|0|2]/"]? ([0-9.]+)? ( )? ([0-9./-]+)? ( /")? ([a-z0-9a-z.///?&=%_/-:+]+)? (/" /")? (. *)/I ", $line, $matches);
echo "<tr><td>". $matches [1]. " </td><td> ". $matches [4]." </td><td> ". $matches [7]." </td><td> ". $matches [9]." </td><td> ". $matches [13]." </td><td> ". $matches [15]." </td><tr> ";
}
}
}
}elseif ($type = = "Robot") {
$lines = File ($doc _path. ' Logs/access_log ');
foreach ($lines as $line _num => $line) {
if (!preg_match ("/robots.txt/i", $line)) {
if (Preg_match ()/(slurp) | ( MSNBot) | (Googlebot) | (Psbot)/I ", Strtolower ($line))) {
Preg_match ("/[0-9.] +)? ([ -]+)? (/[)? ([0-9a-za-z+://]+)? (/])? (/"Get///)?" ([a-z0-9a-z.///?&=%_/-:+]+)? (HTTP//1. [1|0|2]/"]? ([0-9.]+)? ( )? ([0-9./-]+)? ( /")? ([a-z0-9a-z.///?&=%_/-:+]+)? (/" /")? (. *)/I ", $line, $matches);
echo "<tr><td>". $matches [1]. " </td><td> ". $matches [4]." </td><td> ". $matches [7]." </td><td> ". $matches [9]." </td><td> ". $matches [13]." </td><td> ". $matches [15]." </td><tr> ";
}
}
}
}elseif ($type!= "") {
$lines = File ($doc _path. ' Logs/access_log ');
foreach ($lines as $line _num => $line) {
if (Preg_match ("/$type/I", Strtolower ($line)) {
if (!preg_match ("/") $type. " Bot/", Strtolower ($line))) {
Preg_match ("/[0-9.] +)? ([ -]+)? (/[)? ([0-9a-za-z+://]+)? (/])? (/"Get///)?" ([a-z0-9a-z.///?&=%_/-:+]+)? (HTTP//1. [1|0|2]/"]? ([0-9.]+)? ( )? ([0-9./-]+)? ( /")? ([a-z0-9a-z.///?&=%_/-:+]+)? (/" /")? (. *)/I ", $line, $matches);
echo "<tr><td>". $matches [1]. " </td><td> ". $matches [4]." </td><td> ". $matches [7]." </td><td> ". $matches [9]." </td><td> ". $matches [13]." </td><td> ". $matches [15]." </td><tr> ";
}
}
}
}else{
$lines = File ($doc _path. ' Logs/access_log ');
foreach ($lines as $line _num => $line) {
if (Preg_match ("/404/i", $line)) {
if (!preg_match ("/robots.txt/", $line)) {
Preg_match ("/[0-9.] +)? ([ -]+)? (/[)? ([0-9a-za-z+://]+)? (/])? (/"Get///)?" ([a-z0-9a-z.///?&=%_/-:+]+)? (HTTP//1. [1|0|2]/"]? ([0-9.]+)? ( )? ([0-9./-]+)? ( /")? ([a-z0-9a-z.///?&=%_/-:+]+)? (/" /")? (. *)/I ", $line, $matches);
echo "<tr><td>". $matches [1]. " </td><td> ". $matches [4]." </td><td> ". $matches [7]." </td><td> ". $matches [9]." </td><td> ". $matches [13]." </td><td> ". $matches [15]." </td><tr> ";
}
}
}
}
?>
</table>
</body>