2011-02-03 60 views
1

我有一个简单的PHP页面浏览量计数器,并想知道如何能够阻止蜘蛛和机器人被视为具体视图谷歌机器人?PHP的页面浏览量计数器和谷歌机器人的问题

+0

不要阻止你编写自己的脚本,但如果你正在寻找一个柜台,Google Analytics是一个非常强大的工具。如果您想自己创建一个,请忽略此操作。 – user183037 2011-02-03 06:14:52

+0

可能的重复[告诉机器人与人类访问者分开?](http://stackoverflow.com/questions/1717049/tell-bots-apart-from-human-visitors-for-stats) – Quentin 2011-02-03 07:06:11

回答

0

一个简单的方法是实施pagecounter作为图像脚本:

<img src="counter.php" width="1" height="1" alt="Oh I'm just counting"> 

和标记网址为无法访问到蜘蛛/爬虫通过robots.txt,在那里你既可以使用*所有,或只是Googlebot排除它:

User-agent: * 
Disallow: /counter.php 

另一种方法是在脚本只是检查stristr($_SERVER["HTTP_USER_AGENT", "Googlebot"),根本达不到柜台即可。

# Spiders list from http://linksku.com 
$spiders = array('aspseek','abachobot','accoona','acoirobot','adsbot','alexa','alta vista','altavista','ask jeeves','baidu','crawler','croccrawler','dumbot','estyle','exabot','fast-enterprise','fast-webcrawler','francis','geonabot','gigabot','google','heise','heritrix','ibm','iccrawler','idbot','ichiro','lycos','msn','msrbot','majestic-12','metager','ng-search','nutch','omniexplorer','psbot','rambler','seosearch','scooter','scrubby','seekport','sensis','seoma','snappy','steeler','synoo','telekom','turnitinbot','voyager','wisenut','yacy','yahoo'); 
foreach($spiders as $spider) if(stripos($_SERVER['HTTP_USER_AGENT'], $spider) !== false) { 
    $_SERVER['HTTP_CRAWLER'] = true; 
    break; 
} 
if(!isset($_SERVER['HTTP_CRAWLER'])) $_SERVER['HTTP_CRAWLER'] = false; 

然后,你可以检查$_SERVER['HTTP_CRAWLER']值和计数命中阻止脚本:

1

我的网站上添加了此脚本。