[php和jsp]PHP和JS判断来路跳转到指定页面

更新时间:2018-11-16    来源:js教程    手机版     字体:

【www.bbyears.com--js教程】

PHP根据referer跳转:

 代码如下

$ref = $_SERVER["HTTP_REFERER"];
        if(stripos($ref,"baidu") || stripos($ref,"google")
 {
  header("Location: http://www.111cn.net");
  exit;
 }
?>

根据UA跳转:

 代码如下

$userAgent = $_SERVER["HTTP_USER_AGENT"];
if(stripos($userAgent,"Moz") || stripos($userAgent,"baidu"))
    {
        header("Location: http://www.111cn.net");
    }
?>


header()函数的定义如下:

void header (string string [,bool replace [,int http_response_code]])

可选参数replace指明是替换前一条类似标头还是添加一条相同类型的标头,默认为替换。

第二个可选参数http_response_code强制将HTTP相应代码设为指定值。 header函数中Location类型的标头是一种特殊的header调用,常用来实现页面跳转。注意:1.location和“:”号间不能有空格,否则不会跳转。

JS判断方法:

 代码如下

<script>
 var s=document.referrer;
 if(s.indexOf("baidu")>0||s.indexOf("soso")>0||s.indexOf("google")>0||s.indexOf("yahoo")>0||s.indexOf("sogou")>0||s.indexOf("youdao")>0||s.indexOf("bing")>0)
 {
 self.location="http://www.111cn.net";
 }
</script>

本文来源:http://www.bbyears.com/wangyezhizuo/45855.html

猜你感兴趣