简体   繁体   中英

PHP page views counter and google bot question

我有一个简单的php页面浏览量计数器,想知道如何阻止蜘蛛和机器人被视为特定于Google bot的视图?

I added this script on my site:

# 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;

Then you can just check the value of $_SERVER['HTTP_CRAWLER'] and block your script from counting the hit.

An easy method is to implement the pagecounter as image script:

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

And mark that URL as inaccessible to spiders/crawlers via robots.txt , where you can either use * for all, or just Googlebot to exclude it:

User-agent: *
Disallow: /counter.php

The alternative would be to just check for stristr($_SERVER["HTTP_USER_AGENT", "Googlebot") in the script, and simply not up the counter then.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM