Using PHP to enable the page can only be Baidu Gogole Spider access method _php tutorial

Source: Internet
Author: User
The difference between a normal user and a search engine spider crawling is the user agent that is sent,
Look at the website log file can find Baidu Spider name contains Baiduspider, and Google is Googlebot, so we can determine the user agent sent to decide whether to cancel the access of ordinary users, write functions as follows:
Copy CodeThe code is as follows:
function isallowaccess ($directForbidden = FALSE) {
$allowed = Array ('/baiduspider/i ', '/googlebot/i ');
$user _agent = $_server[' http_user_agent ');
$valid = FALSE;
foreach ($allowed as $pattern) {
if (Preg_match ($pattern, $user _agent)) {
$valid = TRUE;
Break
}
}
if (! $valid && $directForbidden) {
Exit ("404 Not Found");
}
 
return $valid;
}

It is OK to refer to this function in the header of the page you want to block access to, and the following two methods are called:
Copy CodeThe code is as follows:
if (!isallowaccess ()) {
Exit ("404 Not Found");
}
Or
Isallowaccess (TRUE);

http://www.bkjia.com/PHPjc/321062.html www.bkjia.com true http://www.bkjia.com/PHPjc/321062.html techarticle ordinary users and search engine spider crawling is the difference between sending the user agent, look at the website log file can find Baidu Spider name contains Baiduspider, and Google is Googlebot, so we ...

  • 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.