PHP iis log analyzer _ PHP Tutorial

Source: Internet
Author: User
PHP iis log analysis program. ****************************************: Iis log analysis analyzes the total number of IP addresses for access requests and search engine captures. * Description: * stores log files in the root directory of the website, and change /************************************* ******************

* Function: analyze iis logs, analyze the total number of IP addresses for access requests, and search engine captures

* Note:

* Place the log file in the root directory of the website and change it to log. log.

* Demo: http://www.zhanzhangpu.com/tools/iislog/

* Http://edu.ITbulo.com/UploadFiles_1485/200909/20090928132201681.gif

* Author: blackli, from the owner

* Problem: the search engine spider address is inaccurate, especially the Google spider address, which is a popular address column in China.

* The table has a large error and has limited capabilities. this problem cannot be solved. If you are interested, refer

* The URL below.

* Reference: http://www.seonewthing.com/GoogleBotCheck.aspx

* Http://googlewebmastercentral.blogspot.com/2006/09/how-to-verify-Googlebot.html

**************************************** ***************/

// Open the log file

$ DOCUMENT_ROOT = $ _ SERVER ['document _ root'];

$ Fp = fopen ("$ DOCUMENT_ROOT/log. log", 'RB ');

If (! $ Fp)

{

Echo 'failed to open the file ';

Exit;

}

// Analyze each line of logs

$ Num_ip = 0; // total number of access IP addresses

$ Ip = array (); // IP address data array. ip [$ I] [0] indicates the ip address, and ip [$ I] [1] indicates the number of times the IP address appears.

While (! Feof ($ fp ))

{

$ Line = fgets ($ fp, 1001 );

If (substr ($ line, 0, 1) = '#')

{

// Obtain the log generation time

If (substr ($ line, 0, 5) = '# date ')

{

$ Date_info = explode ('', $ line );

// Echo 'log generation time: '. $ date_info [1].'. $ date_info [2].'
';

}

}

Else

{

// Obtain the access IP address

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 ++;

}

}

}

// Retrieve search engine spider access times

// List of baidu and Google spider addresses

$ BaiduSpider = array ('192. 123', '192. 123', '192. 123', '61. 220 .');

$ GoogleBot = array ('74. 125. ',' 209. 85. ',' 66. 102. ',' 64. 233. ',' 64. 100', '123. 85. ');

$ Num_Spider = $ num_GoogleBot = 0;

For ($ I = 0; $ I <$ num_ip; $ I ++)

{

// Calculate the number of visits to Baidu Spider

For ($ j = 0; $ j <4; $ j ++)

{

If (substr ($ ip [$ I] [0],) = $ baiduSpider [$ j])

{

$ Num_Spider + = $ ip [$ I] [1];

Continue;

}

}

// Calculate the number of Google spider visits

For ($ j = 0; $ j <6; $ j ++)

{

If (substr ($ ip [$ I] [0],) = $ GoogleBot [$ j])

{

$ Num_GoogleBot + = $ ip [$ I] [1];

Continue;

}

}

}

// Echo 'Baidu Spider request'. $ num_Spider. 'Times
';

// Echo 'Google Spider request'. $ num_GoogleBot. 'Times
';

Fclose ($ fp );

?>

Iis log analysis-Powered by ZhanZhangPu

Log generation time

Total IP request.

Baidu Spider request Times.

Google spider request Times.

IP address list:

For ($ I = 0; $ I <$ num_ip; $ I ++)

{

Echo $ ip [$ I] [0]. ''. $ ip [$ I] [1]. 'times.
';

}

?>

Powered by Webmasters™


Login * function: iis log analysis, analysis of the total number of access IP addresses, search engine captures * Description: * put the log file in the root directory of the website, and modify it...

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.