php 防止爬蟲設定

來源:互聯網
上載者:User

標籤: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 防止爬蟲設定

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.