標籤:php 防止爬蟲設定
php代碼:
650) this.width=650;" src="https://s3.51cto.com/wyfs02/M01/9E/1F/wKioL1mL6fyTx1ImAABB2BMgrVo215.png-wh_500x0-wm_3-wmp_4-s_3261250946.png" title="2017-08-10_130604.png" alt="wKioL1mL6fyTx1ImAABB2BMgrVo215.png-wh_50" />
<?php
//擷取UA資訊
$ua = $_SERVER[‘HTTP_USER_AGENT‘];
//將惡意USER_AGENT存入數組
$now_ua = array(‘FeedDemon ‘,‘BOT/0.1 (BOT for JCE)‘,‘CrawlDaddy ‘,‘Java‘,‘Feedly‘,‘UniversalFeedParser‘,‘ApacheBench‘,‘Swiftbot‘,‘ZmEu‘,‘Indy Library‘,‘oBot‘,‘jaunty‘,‘YandexBot‘,‘AhrefsBot‘,‘MJ12bot‘,‘WinHttp‘,‘EasouSpider‘,‘HttpClient‘,‘Microsoft URL Control‘,‘YYSpider‘,‘jaunty‘,‘Python-urllib‘,‘lightDeckReports Bot‘);
//禁止空USER_AGENT,dedecms等主流採集程式都是空USER_AGENT,部分sql注入工具也是空USER_AGENT
if(!$ua) {
header("Content-type: text/html; charset=utf-8");
die(‘李世龍原創 採集者木有小JJ!‘);
}else{
foreach($now_ua as $value )
//判斷是否是數組中存在的UA
if(eregi($value,$ua)) {
header("Content-type: text/html; charset=utf-8");
die(‘請勿採集本站,採集的木有小JJ!‘);
}
}
如果是vps,那非常簡單,使用curl -A 類比抓取即可,比如:類比宜搜蜘蛛抓取:
650) this.width=650;" src="https://s4.51cto.com/wyfs02/M00/9E/21/wKiom1mL61WwIwhVAAAzztY59ec215.png-wh_500x0-wm_3-wmp_4-s_1631364505.png" title="2017-08-10_131252.png" alt="wKiom1mL61WwIwhVAAAzztY59ec215.png-wh_50" />
本文出自 “李世龍” 部落格,謝絕轉載!
php 防止爬蟲設定