<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 {
// 向自然人显示的内容
} ?>这段向搜索引擎 和 自然访客怎么写,才能实现?
解决方案 »
- 求修改个无限分类递归函数
- 奇怪的json_decode问题,,为什么不能decode呢?
- php访问web service总出乱码
- php怎样删除css文件中的多余空白?
- 在您的php开发过程中,你用过的缓存技术是什么?
- 不同程序和域名之间传送结果集用什么方法
- php访问mysql数据库时SELECT无法准确读取中文记录
- TT15.Com 自助建站系统 整站转让,有实力的公司看看!
- 你好,在"价格"这个字段上无论设计成int 型还是设计成float都不能使加入 价格 后达到这样的这样的效果
- 请教foreach()是什么意思,怎么用?
- 一个奇怪的问题,查入数据库的时候,少一值
- php怎么做删除权限
噢噢,<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;
}
// 正常的页面内容