Created
November 13, 2019 06:15
-
-
Save mrLexx/8f0ad2a44f3d91f4a4b136ccf33758f1 to your computer and use it in GitHub Desktop.
обнаружение ботов
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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