欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

判断搜索引擎来路进行跳转的代码

程序员文章站 2022-05-31 08:46:09
...
求大侠写个搜索引擎来路判断代码进行跳转
如果是百度来的 就跳到 http://aaaa.com
直接输入就不跳转
之前建过人写了代码但是不知道把代码放到那里
比如下面的

$RUrl = $_SERVER ['HTTP_REFERER'];
if (! empty ( $RUrl )) {
$UArray = parse_url ( $RUrl );
$UHost = $UArray ['host'];
switch ($UHost) {
case 'www.baidu.com' :
header ( "Location: http://aaa.com" );
break;
case 'www.google.com' :
header ( "Location: http://bbb.com" );
break;
case 'www.sogou.com' :
header ( "Location: http://ccc.com" );
break;
default :
echo $UHost;
break;
}
}
echo '直接?入';
--------------------------------------------------------------------------------

和下面
章内容摘要:
PHP判断搜索引擎来路跳转代码: ?php $flag = false; $tmp = $_SERVER['HTTP_USER_AGENT']; if(strpos($tmp, 'Googlebot') !== false){ $flag = true; } else if(strpos($tmp, 'Baiduspider') 0){ $flag = true; } else if(strpos($tmp, 'Yahoo! Slurp') !==
PHP判断搜索引擎来路跳转代码:

$flag = false;
$tmp = $_SERVER['HTTP_USER_AGENT'];
if(strpos($tmp, 'Googlebot') !== false){
$flag = true;
} else if(strpos($tmp, 'Baiduspider') >0){
$flag = true;
} else if(strpos($tmp, 'Yahoo! Slurp') !== false){
$flag = true;
} else if(strpos($tmp, 'msnbot') !== false){
$flag = true;
} else if(strpos($tmp, 'Sosospider') !== false){
$flag = true;
} else if(strpos($tmp, 'YodaoBot') !== false || strpos($tmp, 'OutfoxBot') !== false){
$flag = true;
} else if(strpos($tmp, 'Sogou web spider') !== false || strpos($tmp, 'Sogou Orion spider') !== false){
$flag = true;
} else if(strpos($tmp, 'fast-webcrawler') !== false){
$flag = true;
} else if(strpos($tmp, 'Gaisbot') !== false){
$flag = true;
} else if(strpos($tmp, 'ia_archiver') !== false){
$flag = true;
} else if(strpos($tmp, 'altavista') !== false){
$flag = true;
} else if(strpos($tmp, 'lycos_spider') !== false){
$flag = true;
} else if(strpos($tmp, 'Inktomi slurp') !== false){
$flag = true;
}
if($flag == false){
//header("Location: http://www.hake.cc" . $_SERVER['REQUEST_URI']);
require_once("cd.htm");
// 自动转到http://www.hake.cc 对应的网页
// $_SERVER['REQUEST_URI'] 为域名后面的路径
// 或 换成 header("Location: http://www.hake.cc/abc/d.php");
exit();
}
else
{
require_once("news1.htm");
}
?>



--------------------------------------------------------------------------------

JS判断搜索引擎来路跳转代码:

var regexp=//.(sogou|soso|baidu|google|youdao|yahoo|bing|118114|biso|gougou|ifeng|ivc|sooule|niuhu|biso)(/.[a-z0-9/-]+){1,2}///ig;
var where =document.referrer;
if(regexp.test(where))
{
window.location.href='http:hake.cc'
}


--------------------------------------------------------------------------------

回复讨论(解决方案)

你上面的

$RUrl = $_SERVER ['HTTP_REFERER'];
if (! empty ( $RUrl )) {
$UArray = parse_url ( $RUrl );
$UHost = $UArray ['host'];
switch ($UHost) {
case 'www.baidu.com' :
header ( "Location: http://aaa.com" );
break;
case 'www.google.com' :
header ( "Location: http://bbb.com" );
break;
case 'www.sogou.com' :
header ( "Location: http://ccc.com" );
break;
default :
echo $UHost;
break;
}
}
echo '直接?入';

不可以用吗?但是不知道把代码放到哪里?放到你想产生效果的页面啊

我已放了 无效的 你上面的

$RUrl = $_SERVER ['HTTP_REFERER'];
if (! empty ( $RUrl )) {
$UArray = parse_url ( $RUrl );
$UHost = $UArray ['host'];
switch ($UHost) {
case 'www.baidu.com' :
header ( "Locati……

设函数 spider 返回搜索引擎的名字,则有
if(spider() == 'Baiduspider') header('Loction: http://aaaa.com');


复制来的 楼主看看


使用php记录搜索引擎的来路以及用户搜索输入的关键字
http://3aj.cn/php/23.html