Skip to content

Instantly share code, notes, and snippets.

@mrLexx
Created November 13, 2019 06:15
Show Gist options
  • Save mrLexx/8f0ad2a44f3d91f4a4b136ccf33758f1 to your computer and use it in GitHub Desktop.
Save mrLexx/8f0ad2a44f3d91f4a4b136ccf33758f1 to your computer and use it in GitHub Desktop.
обнаружение ботов
<?php
//http://qaru.site/questions/60076/how-to-detect-search-engine-bots-with-php
if (preg_match('/bot|crawl|curl|dataprovider|search|get|spider|find|java|majesticsEO|google|yahoo|teoma|contaxe|yandex|libwww-perl|facebookexternalhit/i', $_SERVER['HTTP_USER_AGENT'])) {
// is bot
}
if (preg_match('/apple|baidu|bingbot|facebookexternalhit|googlebot|-google|ia_archiver|msnbot|naverbot|pingdom|seznambot|slurp|teoma|twitter|yandex|yeti/i', $_SERVER['HTTP_USER_AGENT'])) {
// allowed bot
}
function _bot_detected() {
return (
isset($_SERVER['HTTP_USER_AGENT'])
&& preg_match('/bot|crawl|slurp|spider|mediapartners/i', $_SERVER['HTTP_USER_AGENT'])
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment