PHP Version IIS Log Analyzer

Source: Internet
Author: User
Tags date continue count explode iis log root directory
Description: Place the log file in the root directory of the Web site and rename it to Log.log. Demo: Http://www.jzxue.com/tools/iislog/http://www.jzxue.com/tools/iislog/demo.gif

<?php
/*******************************************************
* Function: IIS log analysis, analysis of the total number of IP access, search engine crawl times
Description
* Place the log file in the root directory of the Web site and rename it to Log.log.
* Demo: http://www.jzxue.com/tools/iislog/
* Http://www.jzxue.com/tools/iislog/demo.gif
* Author: Blackli, build a station to learn to finish
* Problem: Search engine spider address inaccurate, especially Google Spider address, the domestic popular address column
* There are considerable errors in the table and limited capacity to solve the problem. Interested can refer to the
* The URL below.
* Reference: Http://www.seonewthing.com/googleBotCheck.aspx
* http://googlewebmastercentral.blogspot.com/2006/09/how-to-verify-googlebot.html
*******************************************************/

Open log File
$DOCUMENT _root = $_server[' Document_root '];
$fp = fopen ("$DOCUMENT _root/log.log", ' RB ');
if (! $fp)
{
Echo ' Open file failed ';
Exit
}

Analyze each line of log
$num _ip = 0; Total IP Access
$ip = Array (); An array of IP data, where ip[$i][0] is the number of occurrences of the IP address, ip[$i][1]
while (!feof ($FP))
{
$line = fgets ($fp, 1001);
if (substr ($line, 0, 1) = = ' # ')
{
Get Log generation Time
if (substr ($line, 0,5) = = ' #Date ')
{
$date _info = Explode (", $line);
echo ' Log generation Time: '. $date _info[1]. ' '. $date _info[2]. ' </br> ';
}
}
Else
{
Get access IP
if ($line = = ") continue;
$ip _info = Explode (", $line);

for ($j = $num _ip-1, $having _ip = false; $j >= 0; $j-)
{
if ($ip [$j][0] = = $ip _info[6])
{
$having _ip = true;
$ip [$j][1] + +;
Break
}
}
if ($having _ip = = False)
{
$ip [$num _ip][0] = $ip _info[6];
$ip [$num _ip][1] = 1;
$num _ip + +;
}
}
}

Get search engine spider visit times
Baidu, Google spider address List
$baiduSpider = Array (' 220.181 ', ' 159.226 ', ' 202.108 ', ' 61.135 ');
$googleBot = Array (' 74.125. ', ' 209.85. ', ' 66.102. ', ' 64.233. ', ' 64.249 ', ' 209.85. ');

$num _spider = $num _googlebot = 0;
for ($i = 0; $i < $num _ip; $i + +)
{
Count Baidu Spider visit times
for ($j = 0; $j < 4; $j + +)
{

if (substr ($ip [$i][0],0,7) = = $baiduSpider [$j])
{
$num _spider + + $ip [$i][1];
Continue
}
}
Count Google Spider visits
for ($j = 0; $j < 6; $j + +)
{
if (substr ($ip [$i][0],0,7) = = $googleBot [$j])
{
$num _googlebot + + $ip [$i][1];
Continue
}
}
}

Echo ' Baidu spider request '. $num _spider. ' Times <br/> ';
echo ' Google spider request '. $num _googlebot. ' Times <br/> ';
Fclose ($FP);
?>
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<title>iis log Analysis-powered by jzxue</title>
<style type= "Text/css" >
#main {
width:800px;
margin:0 Auto;
border:1px solid #EEE;
}
#main div{
Background: #EEE;
border:2px solid #FBFBFB;
line-height:25px;
font-size:15px;
padding:15px;
}
</style>
<body>
<div id= "Main" >
<div>
A total of <?php echo $num _ip; &GT;IP request .<br/>
Baidu Spider request <?php echo $num _spider;?> Times .<br/>
Google Spider requests <?php echo $num _googlebot;?> times.
</div>
<div>
IP Address List:<br/>
<?php
for ($i = 0; $i < $num _ip; $i + +)
{
echo $ip [$i][0]. ' '. $ip [$i][1]. ' Secondary .<br/> ';
}
?>
</div>
<div>powered by <a href= "http://www.jzxue.com" > Build Station Science </a>™</div>
</div>
</body>



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.