Php iis, log analysis, search engine, crawler record, page 1/2

Source: Internet
Author: User

Note:
Modify the absolute path of IIS logs in the IIS. php file
For example, $ folder = "C:/Windows/system32/logfiles/site log directory/"; // remember to include a slash (/).
(If you use a virtual space, do you not know how to view the absolute path of your site? Upload probes for viewing!
Direct query: http: // site domain name/IIS. php
Local view method: Download the log to the local http: // 127.0.0.1/IIS. php)
Note:
// Site log directory. Note that the directory must have the site User read permission!
// If you download logs to your local machine, modify the web site of Line 1 to the web site of your website. This operation is not necessary and does not affect the analysis result.
// Modify the file name IIS. php at the same time. Code CTRL + H replace all IIS. php files with the file name you want to modify. Otherwise Program An error occurred while running.
// If the IIS log file is too large, the program may time out! We do not recommend that you use it!
Below are PHP Source code :
[Code]
<? PHP
/*
Cowboy IIS log spider crawling log analyzer V1.1 (PhP gb2312)
Author: cowboy
QQ: 172379201
Email: 17gd@163.com
*/
// ================================================ ==================
Header ("Content-Type: text/html; charset = gb2312 ");
// Site log directory. Note that the directory must have the site User read permission!
$ Folder = "C:/Windows/system32/logfiles/w3svc1155699908/"; // remember to include a slash!
$ Pagesize = 25; // you can specify the number of lines displayed on the page!
// ================================
$ Type = addslashes ($ _ Get ['type']);
If ($ type) $ type = base64_decode ($ type );
$ Showfile = addslashes ($ _ Get ['showfile']);
$ Page = addslashes ($ _ Get ['page']);
If (! $ Page) $ page = 1;
// ==================================
// Open the Directory
If (! $ Type ){
If (file_exists ($ folder ))
{
$ Fp = opendir ($ folder );
While (false! = $ File = readdir ($ FP ))
{
If ($ file! = '.' & $ File! = '..')
{
$ File = "$ file ";
$ Arr_file [] = $ file;
}
}
If (is_array ($ arr_file ))
{
For ($ I = count ($ arr_file)-1; $ I> = 0; $ I --)
{
$ Indexstr. = "<tr> <TD Height = \" 25 \ "width = \" 25% \ "> ". date ("Y-m-d", filectime ($ folder. $ arr_file [$ I]). "</TD>
<TD Height = \ "25 \" width = \ "25% \" align = \ "center \"> <a href = \ "iisfile. php? Type = ". base64_encode (baiduspider)." & showfile = ". $ arr_file [$ I]." \ "> Baidu (Baidu) </a> </TD>
<TD Height = \ "25 \" width = \ "25% \" align = \ "center \"> <a href = \ "iisfile. php? Type = ". base64_encode (googlebot)." & showfile = ". $ arr_file [$ I]." \ "> Google </a> </TD>
<TD Height = \ "25 \" width = \ "25% \" align = \ "center \"> <a href = \ "iisfile. php? Type = ". base64_encode (Yahoo ). "& showfile = ". $ arr_file [$ I]. "\"> Yahoo </a> </TD> </tr> ";
}

}
Closedir ($ FP );
$ Html = indexhtml ();
$ Copy = mycopy ();
$ Html = str_replace ("[showlog]", $ indexstr, $ html );
$ Html = str_replace ("[copy]", $ copy, $ html );
Echo $ HTML;
} Else {
Echo "the log directory does not exist or has insufficient permissions. Check the settings! ";
Exit ();
}
} Elseif ($ type = 'baidider ider '){
ECHO Show ($ type, $ folder, $ showfile, $ page, $ pagesize );
} Elseif ($ type = 'googlebot '){
ECHO Show ($ type, $ folder, $ showfile, $ page, $ pagesize );
} Elseif ($ type = 'yahoo '){
ECHO Show ($ type, $ folder, $ showfile, $ page, $ pagesize );
}

Function show ($ type, $ folder, $ showfile, $ page, $ pagesize)
{
If ($ type = 'baidider ider ')
{
$ Title = 'Baidu ';
} Elseif ($ type = 'googlebot '){
$ Title = 'Google ';
} Elseif ($ type = 'yahoo '){
$ Title = 'yahoo ';
}
If ($ type & $ folder & $ showfile)
{
If (file_exists ($ folder. $ showfile ))
{
$ Fp = fopen ($ folder. $ showfile, "R ");
} Else {
Echo "this log file does not exist. Check the settings! ";
Exit;
}
$ J = 0;
$ Y = 0;
$ T = 0;
$ H = 0;
While (! Feof ($ FP ))
{
$ STR = fgets ($ FP );
$ STR = iconv ("UTF-8", "gb2312 // ignore", $ Str );
If (strpos ($ STR, $ type ))
{
$ J ++;
$ Temp []. = $ STR;
$ Tmpcount = explode ("", $ Str );
If ($ tmpcount [11] = 200) $ t ++;
If ($ tmpcount [11] = 304) $ H ++;
If ($ tmpcount [11] = 404) $ y ++;
}
}
Fclose ($ FP );
$ COUNT = count ($ temp );
If ($ page = 1)
{
$ Countshow = $ count;
$ Mynum = $ count-$ pagesize;
} Else {
$ Countshow = $ count-($ page * $ pagesize-$ pagesize );
$ Mynum = $ count-$ page * $ pagesize;
}
$ Pagecount = Ceil (count ($ temp)/$ pagesize );
If ($ page> = $ pagecount)
{
$ Mynum = $ pagecount;
}
$ M = 0;
For ($ I = $ countshow-1; $ I >=$ mynum; $ I --)
{
$ Num = explode ("", $ temp [$ I]);
$ Show. ="
<Tr>
<TD heigth \ "20 \"> ". $ num [0]." ". $ num [1]." </TD>
<TD> ". $ num [9]." </TD>
<TD> <a href = \"". rawurlencode ($ num [5]). "\" target = \ "_ blank \"> ". $ num [5]. "</a> </TD>
<TD> ". $ num [11]." </TD>
</Tr> ";
}
Unset ($ temp );
$ Showpage = "<TD colspan = \" 4 \ "Height = \" 30 \ "align = \" center \ "> each page ". $ pagesize. "current ". $ page. "/$ pagecount ";
$ Showpage. = "<a href = \"? Type = ". base64_encode ($ type)." & showfile = ". $ showfile." \ "> homepage </a> ";
If ($ page! = 1)
{
$ Showpage. = "<a href = \"? Type = ". base64_encode ($ type ). "& showfile = ". $ showfile. "& page = ". ($ page-1 ). "\"> previous page </a> ";
}
If ($ page! = $ Pagecount)
{
$ Showpage. = "<a href = \"? Type = ". base64_encode ($ type ). "& showfile = ". $ showfile. "& page = ". ($ page + 1 ). "\"> next page </a> ";
$ Weei = "<a href = \"? Type = ". base64_encode ($ type ). "& showfile = ". $ showfile. "& page = ". ($ pagecount ). "\"> last page </a> ";
}
$ Showpage. = $ weei. "</TD> ";
If ($ show)
{
$ Html = pagehtml ();
$ Copy = mycopy ();
$ Htmltitle = "cowboy IIS log spider crawling record analyzer-"; // please keep it, thank you!
$ Html = str_replace ("[title]", $ title, $ html );
$ Html = str_replace ("[htmltitle]", $ htmltitle, $ html );
$ Html = str_replace ("[show]", $ show, $ html );
$ Html = str_replace ("[count]", $ J, $ html );
$ Html = str_replace ("

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.