PHP shows different content _php tips to visitors and reptiles

Source: Internet
Author: User
I heard that this method will violate some of the operating principles of search engines, may be punished by the search engines, or even delete the site. So I've just withdrawn this deal until I'm sure it doesn't belong to cheating. Courageous friends can continue to use, but the consequences at their own risk.

The homepage and archive page of this blog displays the article in the form of a list, and the content of the article is loaded when the visitor clicks to expand the article. Because the content part of the article contains a lot of text and pictures, need a lot of loading time and traffic. displaying pages to visitors as quickly as possible can retain a large number of visitors. And for mobile phone users, load time and traffic is more important.

Generally speaking, the homepage of the website is the search engine to visit the most pages, should be as far as possible to show them meaningful content, but to display articles in the form of a list, visitors and search engines can only get the article title information. The content of the article or the 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 reptile, and if so, display the article in general form, otherwise the list of articles will be displayed in the form of a listing. You can use the following PHP method to determine whether you are a reptile:
Copy Code code as follows:

function Is_crawler () {
$userAgent = Strtolower ($_server[' http_user_agent '));
$spiders = Array (
' Googlebot ',//Google crawler
' Baiduspider ',//Baidu Crawler
' Yahoo! Slurp ',//Yahoo crawler
' Yodaobot ',//Youdao Reptile
' MSNBot '//Bing Crawler
More Reptile 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 access comments from high to low. And then show the different content to the reptile and the natural person through the following method

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.