{"id":932,"date":"2021-03-10T18:06:21","date_gmt":"2021-03-10T10:06:21","guid":{"rendered":"http:\/\/www.tra56.com\/?p=932"},"modified":"2021-03-10T18:06:21","modified_gmt":"2021-03-10T10:06:21","slug":"932","status":"publish","type":"post","link":"https:\/\/www.tra56.com\/932.html","title":{"rendered":"PHP \u641c\u7d22\u5f15\u64ce\u8718\u86db\u8bbf\u95ee\u68c0\u6d4b\u548c\u7edf\u8ba1"},"content":{"rendered":"
1.\u5efa\u7acb\u4e00\u4e2a\u6570\u636e\u5e93<\/span><\/p>\n 2.\u901a\u8fc7PHP\u811a\u672c\u68c0\u6d4b\u7edf\u8ba1\u6570\u636e<\/span><\/p>\n 3.\u663e\u793a\u7edf\u8ba1\u6570\u636e<\/span><\/p>\n 4.\u68c0\u6d4b\u662f\u5426\u662f\u722c\u866b<\/span><\/p>\n <\/p>\n","protected":false},"excerpt":{"rendered":" 1.\u5efa\u7acb\u4e00\u4e2a\u6570\u636e\u5e93 create table crawler &nb […]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[26,72,70],"class_list":["post-932","post","type-post","status-publish","format-standard","hentry","category-php","tag-php"],"_links":{"self":[{"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/posts\/932"}],"collection":[{"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/comments?post=932"}],"version-history":[{"count":1,"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/posts\/932\/revisions"}],"predecessor-version":[{"id":933,"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/posts\/932\/revisions\/933"}],"wp:attachment":[{"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/media?parent=932"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/categories?post=932"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/tags?post=932"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}create table crawler \r\n( \r\n crawler_ID bigint(20) unsigned not null auto_increment primary key, \r\n crawler_category varchar(20) not null, \r\n crawler_date datetime not null default '0000-00-00 00:00:00',\r\n crawler_url varchar(50) not null, \r\n crawler_IP varchar(50) not null\r\n)default charset=utf8;<\/pre>\n
<?php\r\n $ServerName = $_SERVER["SERVER_NAME"] ; \r\n\t$ServerPort = $_SERVER["SERVER_PORT"] ; \r\n\t$ScriptName = $_SERVER["SCRIPT_NAME"] ; \r\n\t$QueryString = $_SERVER["QUERY_STRING"]; \r\n\t$serverip = $_SERVER["REMOTE_ADDR"] ; \r\n\t$Url="http:\/\/".$ServerName;\r\n\tif ($ServerPort != "80") \r\n\t{\r\n\t\t$Url = $Url.":".$ServerPort ; \r\n\t} \r\n\t$Url=$Url.$ScriptName;\r\n\tif ($QueryString !="")\r\n\t{\r\n\t\t$Url=$Url."?".$QueryString; \r\n\t} \r\n\t$GetLocationURL=$Url ;\r\n $agent1 = $_SERVER["HTTP_USER_AGENT"]; \r\n\t$agent=strtolower($agent1);\r\n\t$Bot ="";\r\n if (strpos($agent,"bot")>-1)\r\n\t{\r\n\t\t$Bot = "Other Crawler";\r\n\t}\r\n\tif (strpos($agent,"googlebot")>-1)\r\n\t{\r\n\t\t$Bot = "Google";\r\n\t} \r\n if (strpos($agent,"mediapartners-google")>-1)\r\n\t{\r\n\t\t$Bot = "Google Adsense";\r\n\t}\r\n\tif (strpos($agent,"baiduspider")>-1)\r\n\t{\r\n\t\t$Bot = "Baidu";\r\n\t}\r\n\tif (strpos($agent,"sogou spider")>-1)\r\n\t{\r\n\t\t$Bot = "Sogou";\r\n\t}\r\n\tif (strpos($agent,"yahoo")>-1)\r\n\t{\r\n\t\t$Bot = "Yahoo!";\r\n\t}\r\n\tif (strpos($agent,"msn")>-1)\r\n\t{\r\n\t\t$Bot = "MSN";\r\n\t}\r\n\tif (strpos($agent,"ia_archiver")>-1)\r\n\t{\r\n\t\t$Bot = "Alexa";\r\n\t}\r\n\tif (strpos($agent,"iaarchiver")>-1)\r\n\t{\r\n\t\t$Bot = "Alexa";\r\n\t}\r\n\tif (strpos($agent,"sohu")>-1)\r\n\t{\r\n\t\t$Bot = "Sohu";\r\n\t}\r\n\tif (strpos($agent,"sqworm")>-1) \r\n\t{\r\n\t\t$Bot = "AOL";\r\n\t}\r\n\tif (strpos($agent,"yodaoBot")>-1)\r\n\t{\r\n\t\t$Bot = "Yodao";\r\n\t}\r\n\tif (strpos($agent,"iaskspider")>-1)\r\n\t{\r\n\t\t$Bot = "Iask";\r\n\t}\r\n\t \r\n\trequire(".\/dbinfo.php");\r\n\t\r\n date_default_timezone_set('PRC'); \r\n\t$shijian=date("Y-m-d h:i:s", time());\r\n\t\r\n\t\/\/ \u8fde\u63a5\u5230 MySQL \u670d\u52a1\u5668\r\n\t$connection = mysql_connect ($host, $username, $password);\r\n\tif (!$connection) \r\n\t{\r\n \t\tdie('Not connected : ' . mysql_error());\r\n\t}\r\n\t\r\n\t\/\/ \u8bbe\u7f6e\u6d3b\u52a8\u7684 MySQL \u6570\u636e\u5e93\r\n\t$db_selected = mysql_select_db($database, $connection);\r\n\tif (!$db_selected) \r\n\t{\r\n \t\tdie ('Can\\'t use db : ' . mysql_error());\r\n\t}\r\n\t\r\n\t\/\/ \u5411\u6570\u636e\u5e93\u63d2\u5165\u6570\u636e\r\n\t$query = "insert into crawler (crawler_category, crawler_date, crawler_url, crawler_IP) values ('$Bot','$shijian','$GetLocationURL','$serverip')"; \r\n\t\r\n\t$result = mysql_query($query);\r\n\tif (!$result) \r\n\t{\r\n \t\tdie('Invalid query: ' . mysql_error());\r\n\t}\r\n\t \r\n?><\/pre>\n
<?php\r\ninclude '.\/robot.php';\r\ninclude '..\/library\/page.Class.php';\r\n$page = $_GET['page'];\r\n \r\n \r\ninclude '..\/library\/conn_new.php';\r\n\t\t\r\n$count = $mysql -> num_rows($mysql -> query("select * from crawler"));\r\n$pages = new PageClass($count,25,$_GET['page'],$_SERVER['PHP_SELF'].'?page={page}');\r\n$sql = "select * from crawler order by ";\r\n$sql .= "crawler_date desc limit ".$pages -> page_limit.",".$pages -> myde_size;\r\n$result = $mysql -> query($sql);\r\n?>\r\n \r\n<table width="700">\r\n\t<thead>\r\n <tr> \r\n \t<td bgcolor="#CCFFFF"><\/td> \r\n \t<td bgcolor="#CCFFFF" align="center" style="color:#555">\u722c\u866b\u8bbf\u95ee\u65f6\u95f4<\/td> \r\n \t<td bgcolor="#CCFFFF" align="center" style="color:#555">\u722c\u866b\u5206\u7c7b<\/td> \r\n \t<td bgcolor="#CCFFFF" align="center" style="color:#555">\u722c\u866bIP<\/td> \r\n <td bgcolor="#CCFFFF" align="center" style="color:#555">\u722c\u866b\u8bbf\u95ee\u7684URL<\/td> \r\n \t\t<\/tr> \r\n\t<\/thead>\r\n \r\n<?php\r\nwhile($myrow = $mysql -> fetch_array($result)){\r\n?>\r\n<tr>\r\n <td width="30"><img src="..\/images\/topicnew.gif" \/><\/td>\r\n <td width="150" style="font-family:Georgia"><? echo $myrow["crawler_date"] ?><\/td>\r\n <td width="100" style="color:#5F7A77"><? echo $myrow["crawler_category"] ?><\/td>\r\n <td width="100"><? echo $myrow["crawler_IP"] ?><\/td>\r\n <td width="320"><? echo $myrow["crawler_url"] ?><\/td>\r\n<\/tr>\r\n<?php\r\n\t}\r\n?>\r\n <\/table>\r\n<?php\r\n \techo $pages -> myde_write();\r\n?><\/pre>\n
function isRobot() {\r\n static $_robot = null;\r\n if(is_null($_robot)) {\r\n $spiders = 'Bot|Crawl|Spider|slurp|sohu-search|lycos|robozilla';\r\n $browsers = 'MSIE|Netscape|Opera|Konqueror|Mozilla';\r\n if(preg_match("\/($browsers)\/", $_SERVER['HTTP_USER_AGENT'])) {\r\n $_robot\t =\t false ;\r\n } elseif(preg_match("\/($spiders)\/", $_SERVER['HTTP_USER_AGENT'])) {\r\n $_robot\t =\t true;\r\n } else {\r\n $_robot\t =\t false;\r\n }\r\n }\r\n return $_robot;\r\n}<\/pre>\n