PHP to determine whether a visitor is a search engine spider's function code _php tips

Source: Internet
Author: User
Copy Code code as follows:

/**
* To determine whether the search engine spider
*
* @author Eddy
* @return BOOL
*/
function Iscrawler () {
$agent = Strtolower ($_server[' http_user_agent '));
if (!empty ($agent)) {
$spiderSite = Array (
"Tencenttraveler",
"Baiduspider+",
"Baidugame",
"Googlebot",
"MSNBot",
"Sosospider+",
"Sogou web Spider",
"Ia_archiver",
"Yahoo! Slurp",
"Youdaobot",
"Yahoo slurp",
"MSNBot",
"Java (often spam bot)",
"Baiduspider",
"Voila",
"Yandex bot",
"Bspider",
"Twiceler",
"Sogou Spider",
"Speedy Spider",
"Google AdSense",
"Heritrix",
"Python-urllib",
"Alexa (IA archiver)",
"Ask",
"Exabot",
"Custo",
"Outfoxbot/yodaobot",
"YaCy",
"Surveybot",
"Legs",
"Lwp-trivial",
"Nutch",
"Stackrambler",
"The Web Archive (IA archiver)",
"Perl Tool",
"Mj12bot",
"Netcraft",
"Msiecrawler",
"WGet Tools",
"Larbin",
"Fish Search",
);
foreach ($spiderSite as $val) {
$str = Strtolower ($val);
if (Strpos ($agent, $STR)!== false) {
return true;
}
}
} else {
return false;
}
}


The internet can be found a lot, but are all the same copy to copy, and not comprehensive, I have organized a more comprehensive code:

Copy Code code as follows:

function Is_spider () {
$robot = 0;
$USER _agent = strtolower ($_server[' http_user_agent '));
if (Strpos ($USER _agent, "Bot")) $robot = 1;
if (Strpos ($USER _agent, "spider")) $robot = 1;
if (Strpos ($USER _agent, "slurp")) $robot = 1;
if (Strpos ($USER _agent, "Mediapartners-google")) $robot = 1;
if (Strpos ($USER _agent, "Fast-webcrawler")) $robot = 1;
if (Strpos ($USER _agent, "AltaVista")) $robot = 1;
if (Strpos ($USER _agent, "Ia_archiver")) $robot = 1;
if ($robot = = 1) {
Do something
}
Return ";
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.