PHP統(tǒng)計(jì)nginx訪問(wèn)日志中的搜索引擎抓取404鏈接頁(yè)面路徑
我在服務(wù)器上有每天切割nginx日志的習(xí)慣,所以針對(duì)每天各大搜索引擎來(lái)訪,總能記錄一些404頁(yè)面信息,傳統(tǒng)上我只是偶爾分析下日志,但是對(duì)于很多日志信息的朋友,人工來(lái)篩選可能不是一件容易的事情,這不我個(gè)人自己慢慢研究了一點(diǎn)點(diǎn),針對(duì)谷歌、百度、搜搜、360搜索、宜搜、搜狗、必應(yīng)等搜索引擎的404訪問(wèn)生成為一個(gè)txt文本文件,直接上代碼test.php。
<?php
//訪問(wèn)test.php?s=google
$domain='http://m.fzitv.net';
$spiders=array('baidu'=>'Baiduspider','360'=>'360Spider',
'google'=>'Googlebot','soso'=>'Sosospider','sogou'=>
'Sogou web spider','easou'=>'EasouSpider','bing'=>'bingbot');
$path='/home/nginx/logs/'.date('Y/m/').(date('d')-1).'/access_www.txt';
$s=$_GET['s'];
if(!array_key_exists($s,$spiders)) die();
$spider=$spiders[$s];
$file=$s.'_'.date('ym').(date('d')-1).'.txt';
if(!file_exists($file)){
$in=file_get_contents($path);
$pattern='/GET (.*) HTTP\/1.1" 404.*'.$spider.'/';
preg_match_all ( $pattern , $in , $matches );
$out='';
foreach($matches[1] as $k=>$v){
$out.=$domain.$v."\r\n";
}
file_put_contents($file,$out);
}
$url=$domain.'/silian/'.$file;
echo $url;
好就這樣了。沒(méi)有什么高深的技術(shù),只有動(dòng)手寫(xiě)的過(guò)程。
- php 定義404頁(yè)面的實(shí)現(xiàn)代碼
- ThinkPHP3.2.3框架實(shí)現(xiàn)的空模塊、空控制器、空操作,跳轉(zhuǎn)到錯(cuò)誤404頁(yè)面圖文詳解
- thinkphp框架下404頁(yè)面設(shè)置 僅三步
- ThinkPHP 404頁(yè)面的設(shè)置方法
- ThinkPHP訪問(wèn)不存在的模塊跳轉(zhuǎn)到404頁(yè)面的方法
- php使用curl判斷網(wǎng)頁(yè)404(不存在)的方法
- PHP header()函數(shù)使用詳細(xì)(301、404等錯(cuò)誤設(shè)置)
- php 404錯(cuò)誤頁(yè)面實(shí)現(xiàn)代碼
- 用php來(lái)改寫(xiě)404錯(cuò)誤頁(yè)讓你的頁(yè)面更友好
- php 智能404跳轉(zhuǎn)代碼,適合換域名沒(méi)改變目錄的網(wǎng)站
- thinkPHP5框架設(shè)置404、403等http狀態(tài)頁(yè)面的方法
- php簡(jiǎn)單檢測(cè)404頁(yè)面的方法示例
相關(guān)文章
ThinkPHP菜單無(wú)極分類(lèi)實(shí)例講解
微信公眾平臺(tái)實(shí)現(xiàn)獲取用戶OpenID的方法
PHP不使用遞歸的無(wú)限級(jí)分類(lèi)簡(jiǎn)單實(shí)例
ThinkPHP3.1新特性之查詢條件預(yù)處理簡(jiǎn)介
實(shí)例講解php數(shù)據(jù)訪問(wèn)

