<?php
/*
Code-Schnipsel zur Erkennung von Suchmaschinen-Spidern
Copyright (C) 2004/05 Matthias Mohr, MaMo Net (http://www.mamo-net.de)
Version: 1.0.0 (December 14, 2004)
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
// Um das Script mit PHP < 4.1.0 kompatibel zu machen
$_SERVER = &$HTTP_SERVER_VARS;
}
// Function zum erkennen der SuMa
function BotDetection () {
// Array mit Suchmaschinen-Daten
// Pro SuMa ein Array im Array $bots
// user_agent enthält den HTTP_USER_AGENT der SuMa
// name enthält den öffentlichen Namen der SuMa
'user_agent' => 'Googlebot',
'name' => 'Google',
),
'user_agent' => 'Mediapartners-Google',
'name' => 'Google',
),
'user_agent' => 'msnbot',
'name' => 'MSN (Microsoft Network)',
),
'user_agent' => 'Mozilla/5.0 (compatible; Yahoo! Slurp;',
'name' => 'Yahoo',
)
);
// prüfe jede SuMa
foreach ($bots as $spider) {
// Prüfe ob der HTTP_USER_AGENT vorhanden ist
if (stristr($_SERVER['HTTP_USER_AGENT'], $spider['user_agent']) !== FALSE) {
// Wenn ein Spider identifiziert wurde, gib den Namen zurück
return $spider['name'];
}
}
// wenn kein Spider identifiziert werden konnte melden FALSE zurück
return false;
}
// Rufe die Funktion auf
$bot = BotDetection();
if ($bot) {
// Wenn ein gültiger Bot gegeben ist, mache etwas
echo "Hallo Suchmaschine, $bot";
}
else {
// Wenn kein gültiger Bot gegeben ist, mache etwas anderes
echo "Hallo menschlicher Gast";
}
?>