Home > php教程 > php手册 > body text

PHP和JS判断来路跳转到指定页面

WBOY
Release: 2016-06-13 09:52:08
Original
956 people have browsed it

今天小编来给各位同学介绍一个比较综合的PHP和JS判断来路跳转到指定页面,希望此方法对各位同学会有所帮助哦。

PHP根据referer跳转:

 代码如下 复制代码

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

根据UA跳转:

 代码如下 复制代码

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


header()函数的定义如下:

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

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

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

JS判断方法:

 代码如下 复制代码

<script><br /> var s=document.referrer;<br /> 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)<br /> {<br /> self.location="http://www.bKjia.c0m";<br /> }<br /> </script>

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!