[PHP] Counter die Bots nicht mitzählen

digiTALE

Lt. Junior Grade
Registriert
Juli 2004
Beiträge
270
Seid gegrüsst,

Auf meiner Homepage habe ich ein Counter mit IP Reload Sperre. Jedenfalls wird die Besucherzahl von Bots verfälscht! Wie kann ich so eine Art Blackliste integrieren und die Bots ausschliessen, also diese nicht mitzählen!?

Mein Counter habe ich von www.webmaster-resource.de
PHP:
<?php
$DateinameCount = "count.txt";
$DateinameIP    = "ip.txt";
$Zeitsperre     = 86400; // Sekunden

#######################################
$Gefunden = FALSE;
$IPListe = file($DateinameIP);
 
if(count($IPListe) > 0)
{
foreach($IPListe as $Zeile)
{
$GesplitteteZeile = explode("|", $Zeile);
 
if(($GesplitteteZeile[0]+$Zeitsperre) > time())
{
$NeueIPListe[] = trim($Zeile)."\n";
}
}

if(count($NeueIPListe) > 0)
{
foreach($NeueIPListe as $Zeile)
{
$GesplitteteZeile = explode("|", $Zeile);

if(trim($GesplitteteZeile[1]) == $_SERVER['REMOTE_ADDR'])
{
$Gefunden = TRUE;
}
}
}
}

$FilePointerIP = fopen($DateinameIP, "w");

if(count($IPListe) > 0 && count($NeueIPListe) > 0)
{
foreach($NeueIPListe as $Zeile)
{
fwrite($FilePointerIP, trim($Zeile)."\n");
}
}
if(!$Gefunden)
{
fwrite($FilePointerIP, time()."|".$_SERVER['REMOTE_ADDR']."\n");
}
fclose($FilePointerIP
);
$FilePointerCount = fopen($DateinameCount, "r+");

$Counter = fread($FilePointerCount, filesize($DateinameCount));

if(!$Gefunden)
{
$Counter++;
rewind($FilePointerCount);
fwrite($FilePointerCount, $Counter);
}
fclose($FilePointerCount);

echo$Counter;
?>

mfg digiTALE
 
Ich glaube nicht dass das Sinn macht, da die Bots ihre IPs ständig ändern. Ansonsten würde ich um das ganze eine if-Abfrage setzen, die den Code nur ausführt wenn die IP des Besuchers nicht auf deiner Liste steht.
 
Das ist richtig aber man kann, denk ich mal, per $_SERVER['HTTP_USER_AGENT']; vergleichen. Irgendwie machen es doch auch die PageRank Seiten das auch!

z. B. Google Bot = Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)

Muss ja irgendwie zu realisieren sein, nur fehlt mir der Ansatz wie!

mfg digiTALE
 
Hallo,

musst abfragen ob $_SERVER['HTTP_USER_AGENT'] != "Mozilla/2.0 (compatible; Ask Jeeves/Teoma; +http://about.ask.com/en/docs/about/webmasters.shtml)"
könntest eventuell noch mehrer in eine Array abfragen und dann in einem Boolean speicher ob einer der Werte wahr ist.

MFG
 
@ tewes

Jap, das ist eine gute Idee, werde die Bots in einen Array schreiben. Kenn auch eine Seite wo echt viele Bots mit ihren Namen angezeigt werden. Wem es interessiert kann ich ja in den nächsten Tagen das fertige Script mal posten!

mfg digiTALE
 
Ich muss schon sagen, dass dein Problem recht interessant ist :)

Ich würde einfach mal Alle Zugriffe in eine Datenbank loggen, samt $_SERVER['HTTP_USER_AGENT'].
Wenn du jetzt ein SELECT DISTINCT machst siehst du jeden $_SERVER['HTTP_USER_AGENT'], der je auf deiner seite war.
Diese kannst du in eine extra Tabelle eintragen, die dann eine 2. Spalte hat, die zb 0 ist, wenn es ein bot ist, und 1, wenn es kein bot ist.
Am ende kannst du die anzahl der tatsächlichen Seitenaufrufe dann rausfinden, indem du folgenden befehl auf die Datenbank ausführst: select count(idx) from aufrufe where USER_AGENT not in (select USER_AGENT from USERAGENTS where bot = false)

Ist nicht so leicht aber effizient, da du praktisch die volle kontrolle hast und fehler im nachhinein verbessern kannst!

David


Edith: Hab dir mal ne PM geschickt, ich kann dir gerne helfen weils micht jetzt selbst interessiert :)
 
Ja, denke mal das ich eine vernünftige Lösung gefunden habe!

PHP:
$findbot =  array(
	"W3C_Validator/1.432.2.10",
	"Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)",
	"msnbot/1.0 (+http://search.msn.com/msnbot.htm)",
	"msnbot/0.9 (+http://search.msn.com/msnbot.htm)",
	"Mozilla/2.0 (compatible; Ask Jeeves/Teoma; +http://about.ask.com/en/docs/about/webmasters.shtml)",
	"Mozilla/5.0 (compatible; Yahoo! Slurp; http://help.yahoo.com/help/us/ysearch/slurp)",
	"ia_archiver",
	"ichiro/2.0 (http://help.goo.ne.jp/door/crawler.html)",
	"Francis/2.0 (francis@neomo.de http://www.neomo.de/pages/crawler.php)",
	"IRLbot/2.0 (compatible; MSIE 6.0; http://irl.cs.tamu.edu/crawler)",
	"TurnitinBot/2.0 http://www.turnitin.com/robot/crawlerinfo.html",
	"Seekbot/1.0 (http://www.seekbot.net/bot.html) HTTPFetcher/2.2",
	"MJ12bot/v1.0.8 (http://majestic12.co.uk/bot.php?+)",
	"p15188177.pureserver.info",
	"vBSEO (http://www.vbseo.com)",
	"TMCrawler",
);

if ($_SERVER['HTTP_USER_AGENT'] == $findbot ) {
	print "";
} else {

Counterdaten usw...

}

Habe es noch nicht wirklich getestet aber sollte so auf den ersten blick richtig sein!?

Mfg chriz
 
Hallo digiTALE,

so wird der kein Bot finde.

Du musst den Array noch mit einer Schleife durchlaufen oder die Funktion in_array Benutzen ob http_user_agent in dem Array ist.

MFG

tewes
 
uijui, also dann so hier!?

PHP:
$findbot =  array(
    "W3C_Validator/1.432.2.10",
    "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)",
    "msnbot/1.0 (+http://search.msn.com/msnbot.htm)",
    "msnbot/0.9 (+http://search.msn.com/msnbot.htm)",
    "Mozilla/2.0 (compatible; Ask Jeeves/Teoma; +http://about.ask.com/en/docs/about/webmasters.shtml)",
    "Mozilla/5.0 (compatible; Yahoo! Slurp; http://help.yahoo.com/help/us/ysearch/slurp)",
    "ia_archiver",
    "ichiro/2.0 (http://help.goo.ne.jp/door/crawler.html)",
    "Francis/2.0 (francis@neomo.de http://www.neomo.de/pages/crawler.php)",
    "IRLbot/2.0 (compatible; MSIE 6.0; http://irl.cs.tamu.edu/crawler)",
    "TurnitinBot/2.0 http://www.turnitin.com/robot/crawlerinfo.html",
    "Seekbot/1.0 (http://www.seekbot.net/bot.html) HTTPFetcher/2.2",
    "MJ12bot/v1.0.8 (http://majestic12.co.uk/bot.php?+)",
    "p15188177.pureserver.info",
    "vBSEO (http://www.vbseo.com)",
    "TMCrawler",
);

if (in_array($_SERVER['HTTP_USER_AGENT'], $findbot )) {
    print "";
} else {

Counterdaten usw...

}

mfg chriz
 
Zuletzt bearbeitet:
Ja funktioniert auch!

Hab noch einwenig die Liste erweitert:
PHP:
$findbot =  array(
	"AdUpdater/2.0 (http://www.AdUp.net)",
	"amaya/9.51 libwww/5.4.0",
	"Anonymisiert durch Steganos Internet Anonym 2006",
	"Baiduspider+(+http://www.baidu.com/search/spider.htm)",
	"curl/7.9.8 (i686-pc-linux-gnu) libcurl 7.9.8 (OpenSSL 0.9.6b) (ipv6 enabled)",
	"Cynthia 1.0",
	"eBay Relevance Ad Crawler powered by contentDetection (www.mindup.de)",
	"Francis/2.0 (francis@neomo.de http://www.neomo.de/)",
	"Googlebot-Image/1.0",
	"HTML2JPG Blackbox, http://www.html2jpg.com",
	"ia_archiver",
	"IBrowse/2.2 (AmigaOS V45)",
	"ichiro/2.0 (http://help.goo.ne.jp/door/crawler.html)",
	"IRLbot/2.0 (compatible; MSIE 6.0; http://irl.cs.tamu.edu/crawler)",
	"Jigsaw/2.2.5 W3C_CSS_Validator_JFouffa/2.0",
	"lib-www",
	"Mediapartners-Google/2.1",
	"MetaTagRobot/ (http://www.widexl.com/remote/search-engines/metatag-analyzer.html)",
	"MJ12bot/v1.0.8 (http://majestic12.co.uk/bot.php?+)",
	"Mozilla/2.0 (compatible; Ask Jeeves/Teoma; +http://about.ask.com/en/docs/about/webmasters.shtml)",
	"Mozilla/2.0 (compatible; MS FrontPage 4.0)",
	"Mozilla/2.0 (compatible; MS FrontPage 5.0)",
	"Mozilla/3.0 (compatible; Indy Library)",
	"Mozilla/3.01 (compatible;)",
	"Mozilla/3.01Gold (Macintosh; I; 68K)",
	"Mozilla/4.0",
	"Mozilla/4.0",
	"Mozilla/4.0 (compatible)",
	"Mozilla/4.0 (compatible; BorderManager 3.0)",
	"Mozilla/4.0 (compatible; MS FrontPage 6.0)",
	"Mozilla/4.0 (compatible; MSIE 6.0; SaferSurf)",
	"Mozilla/4.0 (compatible; Netcraft Web Server Survey)",
	"Mozilla/4.0 (PSP (PlayStation Portable); 2.00)",
	"Mozilla/4.5 [de] (Macintosh; I; PPC)",
	"Mozilla/4.61 [ja] (X11; I; Linux 2.2.13-33cmc1 i686)",
	"Mozilla/5 (Windows; rv:1.8.0.6) Gecko",
	"Mozilla/5.0",
	"Mozilla/5.0 (Amiga; U; AmigaOS 3.1; de-DE; rv:1.8b4)",
	"Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)",
	"Mozilla/5.0 (compatible; Yahoo! Slurp; http://help.yahoo.com/help/us/ysearch/slurp)",
	"Mozilla/5.0 (Windows; Googlebot 2.1; Windows NT 5.1; de; rv:1.8.0.6) Gecko/20060728",
	"Googlebot 2.1",
	"Mozilla/5.0 (Windows; U; Win 9x 4.90; de-AT; rv:1.8a3) Gecko/20040817 (No IDN)",
	"Mozilla/5.0 (Windows; U; Windows NT 5.0; de; rv:1.8.0.6) Gecko/20060728 Googlebot 2.1",
	"Mozilla/5.0 (Windows; U; Windows NT 5.0; de; rv:1.8.0.6) Gecko/20060728 Googlebot2.1",
	"Mozilla/5.0 (Windows; U; Windows NT 5.0; de; rv:1.8.0.7) Gecko/20060909 Googlebot 2.1",
	"Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.8) Gecko/20051111 Googlebot 2.1",
	"Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.8.0.2) Gecko/20060308 Googlebot 2.1",
	"Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.8.0.4) Gecko/20060508 Googlebot 2.1",
	"Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.8.0.4) Gecko/20060508 Googlebot 2.1",
	"Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.8.0.4) Gecko/20060508 Googlebot 2.1",
	"Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.8.0.5) Gecko/20060719 Googlebot2.",
	"Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.8.0.6) Gecko/20060728 Googlebot 2.1",
	"Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.8.0.6) Gecko/20060728 Googlebot2.1",
	"Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.8.0.7) Gecko/20060909 Googlebot 2.1",
	"Mozilla/spoofed/you",
	"msnbot/0.9 (+http://search.msn.com/msnbot.htm)",
	"msnbot/1.0 (+http://search.msn.com/msnbot.htm)",
	"Nutscrape/1.0 (CP/M; 8-bit)",
	"ozelot/2.7.3 (Search engine indexer; www.flying-cat.de/ozelot; ozelot@flying-cat.de)",
	"p15188177.pureserver.info",
	"Rightscripts",
	"Seekbot/1.0 (http://www.seekbot.net/bot.html) HTTPFetcher/2.1",
	"Seekbot/1.0 (http://www.seekbot.net/bot.html) HTTPFetcher/2.2",
	"Snappy/1.1 ( http://www.urltrends.com/ )",
	"SquidClamAV_Redirector 1.7.0",
	"TMCrawler",
	"topSUBMIT.de LoadControl/1.2",
	"topSUBMIT.de LoadControl/1.2",
	"TurnitinBot/2.0 http://www.turnitin.com/robot/crawlerinfo.html",
	"unknown/1.0 (CP/M; 8-bit)",
	"vBSEO (http://www.vbseo.com)",
	"W3C-checklink/4.2 [4.20] libwww-perl/5.803",
	"W3C-checklink/4.2.1 [4.21] libwww-perl/5.803",
	"W3C_Validator/1.432.2.10",
	"WebCorp/1.0",
	"WebReaper [info@webreaper.net]",
	"WebWasher 3.4",
	"winhttprequest",
	"xedo (compatible; MSIE 6.0; Windows NT 5.1; SV1)",
	"Xxx",

// Boese Spider - Bots (halten sich nict an die robots.txt

	"Java/1.4.2_03",
	"Java/1.5.0_06",
	"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50215)",
	"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)",
	"SEO search Crawler/0.2.15 abuse@seo-crawler.de",
	"Snoopy v1.2",

);

if (in_array($_SERVER['HTTP_USER_AGENT'], $findbot )) {
    print "";
} else {

Counterdaten usw...

}

Wer dann wirklich alle Bots noch hinzufügen will der gehe auf http://www.psychedelix.com/agents/index.shtml, dort sind vll. an die 500 Bots aufgelistet. Na dann viel Spass :lol:

Mfg chriz
 
Warum kompliziert wenn's einfach geht? :freaky:

Bots laden keine Grafiken, also einfach den Counter als Bild tarnen. :)

HTML:
<img src="counter.php">
 
davidbaumann schrieb:
Google Images schon, denk ich mal.
Wie hast du die Bots rausbekommen?

David

Die Liste der Bots habe ich von http://www.browser-statistik.de, wo ich auch übrigens angemldet bin :evillol:

Will auf jedenfall nochma versuchen das Die Sperre auch IP Adressen filtert, da es auch viele Spam oder Spider Bots gibt, die sich als normaler Browser tarnen!!

Mfg chriz
 
Hallo Ihr,

wäre es denn nicht einfacher, nur Teile des UserAgents abzufragen, anstatt den kompletten String?

Beispiel: Taucht im String das Wort "Googlebot" auf, wird der Ankömmling als Bot erkannt (welcher echte Nutzer nennt sich schon Googlebot). So könnte man sich vielleicht die Unterscheidung nach -zig verschiedenen Googlebots, die Aktualisierung der Einträge und einen großen Teil des Arrays ersparen. Oder liege ich da falsch?

Viele Grüße
Mondschatten


Schwarz kann auch glänzen.
 
Zuletzt bearbeitet:
Wäre natürlich eine Erleichterung! Aber welchen Befehl nehm ich denn, der nach bestimmen teilen in einem Array sucht?
Habe nix passendes gefunden.

Mfg chriz
 
Eleganter und performanter wäre die Suche nach bot- und spider-typischen Mustern innerhalb des UA-Strings mit Hilfe von regulären Ausdrücken, auf diese Weise muß nicht jedes Mal über ein stetig wachsendes Array iteriert werden.

greetings, Keita
 
Vielleicht so, wenn man auf das Array zurückgreifen will?

PHP:
$isbot=false;

foreach($botarray as $bot)
{     
	$pos = strpos ($_SERVER['HTTP_USER_AGENT'], $bot);
	if ($pos <> false):
		$isbot=true;
	endif;
}

if ($isbot==false):

  // ...wenn kein Bot, dann weiter

Das Array soll dann nur noch einzelne Begriffe wie "Googlebot" usw. enthalten, nicht mehr komplette UA-Angaben.

Grüsse
Mondschatten
 
Ich würde eine Stored Procedure nehmen die bei jedem seitenabruf gestartet wird, prüft, ob es sich um einen bot handelt und wenn nicht zählts den counter hoch!

Gruss,
David
 

Ähnliche Themen

J
Antworten
5
Aufrufe
1.079
C
M
Antworten
3
Aufrufe
1.022
Zurück
Oben