这么做一个判断来访地址并根据不同域名跳转指定显示页面

论坛: 

首先收藏一个代码:
分享一个判断来访地址并根据不同域名跳转的程序:
<?
function getDomain($url){
$pattern = "/[\w-]+\.(com|net|org|gov|cc|biz|info|cn|co)(\.(cn|hk))*/";
preg_match($pattern, $url, $matches);
if(count($matches) > 0) {
return $matches[0];
}else{
$rs = parse_url($url);
$main_url = $rs["host"];
if(!strcmp((sprintf("%u",ip2long($main_url))),$main_url)) {
return $main_url;
}else{
$arr = explode(".",$main_url);
$count=count($arr);
$endArr = array("com","net","org","3322","cn");//com.cn net.cn 等情况
if (in_array($arr[$count-2],$endArr)){
$domain = $arr[$count-3].".".$arr[$count-2].".".$arr[$count-1];
}else{
$domain = $arr[$count-2].".".$arr[$count-1];
}
return $domain;
}
}
}

$domain = getDomain(strtolower($_SERVER["SERVER_NAME"]));

$arrays=array(
'baidu.com'=>'http://www.2oa.net/node/1',
'google.com'=>'http://www.2oa.net/node/2',
'yahoo.com.cn'=>'http://www.2oa.net/node/3',
'alibaba.com.cn'=>'http://www.2oa.net/node/4',
'dsjz.cn'=>'http://www.2oa.net/node/5'
//这里可以加很多你想控制的你的域名跳转地址。如果量太多就用mysql来存储管理吧。
);

$url = $arrays[$domain];
header("Location: " . $url);
?>
把这个保存成index.php,放到默认的目录下,把所有域名都指向过去,就可以用这单一文件控制跳转地址。
可能对于用跳转来利用闲置域名的朋友有用,所以分享下。