<script>
function is_crawler() {
$userAgent = strtolower($_SERVER['HTTP_USER_AGENT']);
$spiders = array(
'Googlebot', // Google 爬虫
'Baiduspider', // 百度爬虫
'Yahoo! Slurp', // 雅虎爬虫
'YodaoBot', // 有道爬虫
'msnbot' // Bing爬虫
// 更多爬虫关键字
);
foreach ($spiders as $spider) {
$spider = strtolower($spider);
if (strpos($userAgent, $spider) !== false) {
return true;
}
}
return false;
}
</script>
<?php if(is_crawler()) {
// 向搜索引擎显示的内容
} else {
// 向自然人显示的内容
} ?><?php if(is_crawler()) {
// 向搜索引擎显示的内容
} else {
// 向自然人显示的内容
} ?>这段向搜索引擎 和 自然访客怎么写,才能实现?
噢噢,<script>是<?php的意思,凌乱了。区别就在于<head>里各种meta打给爬虫的时候齐全一点,keywords,description
2、你可把 is_crawler 函数放在独立的文件中,在需要的地方引入进来
is_crawler.php
<?php
function is_crawler() {
$userAgent = strtolower($_SERVER['HTTP_USER_AGENT']);
$spiders = array(
'Googlebot', // Google 爬虫
'Baiduspider', // 百度爬虫
'Yahoo! Slurp', // 雅虎爬虫
'YodaoBot', // 有道爬虫
'msnbot' // Bing爬虫
// 更多爬虫关键字
);
foreach ($spiders as $spider) {
$spider = strtolower($spider);
if (strpos($userAgent, $spider) !== false) {
return true;
}
}
return false;
}在需要时
include_once 'is_crawler.php';例:
<?php
include_once 'is_crawler.php';
if(is_crawler()) {
include '给搜索引擎看的页面.php';
exit;
}
// 正常的页面内容