PHP implementation _php tutorials for displaying different content to visitors and crawlers

Source: Internet
Author: User
In order to improve the user experience of the Web page, we often do something that is not very friendly to the search engine, but in some cases this is not irreversible, you can provide a good user experience and SEO by displaying different content to natural and search engine robots.

Heard that this method will violate some of the search engine operating principles, may be punished by various search engines, or even delete the site. So I've just withdrawn from this deal until I'm sure it doesn't belong to cheating. A friend with courage can continue to use, but the consequences are self-esteem.

The homepage and archive page of this blog is displayed as a list of articles, and the content of the article is loaded only when the visitor clicks to expand the article. Because the content part of the article contains a lot of text and pictures, it takes a lot of loading time and traffic. A large number of visitors can be retained as soon as possible by showing the page to visitors. For mobile users, load times and traffic are more important.

Generally speaking, the homepage of the website is the most visited page of search engine, should show them meaningful content as far as possible, but to display the article in the form of list, the visitor and search engine can only get the article title information. article content or abstract (especially the first sentence of the article) is extremely important for SEO, so we have to try to send these content to the crawler.

OK, we can use the User Agent to determine whether the visitor is a crawler, if so, the article is displayed in general form, otherwise the list of the article list. You can use the following PHP method to determine whether it is a crawler:

Copy to ClipboardWhat to refer to: [www.bkjia.com]function Is_crawler () {
$userAgent = Strtolower ($_server[' http_user_agent ');
$spiders = Array (
' Googlebot ',//Google crawler
' Baiduspider ',//Baidu Crawler
' Yahoo! slurp ',//Yahoo crawler
' Yodaobot ',//Youdao crawler
' MSNBot '//Bing Crawler
More crawler Keywords
);
foreach ($spiders as $spider) {
$spider = Strtolower ($spider);
if (Strpos ($userAgent, $spider)!== false) {
return true;
}
}
return false;
}

This is the way I use the crawler to sort by accessing comments from high to low. The following methods are then used to display different content to reptiles and natural persons.

http://www.bkjia.com/PHPjc/364381.html www.bkjia.com true http://www.bkjia.com/PHPjc/364381.html techarticle in order to improve the user experience of web pages, we often do things that are not very friendly to search engines, but in some cases this is not irreparable and can be passed to natural persons and search engines ...

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