Home >Backend Development >PHP Tutorial >PHP and JS determine the origin and jump to the specified page_PHP tutorial

PHP and JS determine the origin and jump to the specified page_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:50:08998browse

Today, the editor will introduce to you a more comprehensive PHP and JS method to determine the source and jump to the specified page. I hope this method will be helpful to all students.

PHP jumps according to referer:

The code is as follows
 代码如下 复制代码

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

Copy code

 代码如下 复制代码

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

$ref = $_SERVER['HTTP_REFERER'];
If(stripos($ref,"baidu") || stripos($ref,"google")

{

header("Location: http://www.bKjia.c0m");

exit;

}

?>

 代码如下 复制代码

<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>

Jump according to UA:
The code is as follows
Copy code

$userAgent = $_SERVER['HTTP_USER_AGENT']; { header("Location: http://www.bKjia.c0m"); } ?> The header() function is defined as follows: void header (string string [,bool replace [,int http_response_code]])

The optional parameter replace specifies whether to replace the previous similar header or add a header of the same type. The default is replacement.
The second optional parameter http_response_code forces the HTTP response code to the specified value. The Location type header in the header function is a special header call, often used to implement page jumps. Note: 1. There cannot be a space between location and ":", otherwise it will not jump. JS judgment method:
The code is as follows Copy code
<script> var s=document.referrer; if(s.indexOf("baidu")>0||s.indexOf("soso")>0||s.indexOf("google")>0||s.indexOf("yahoo")&gt ;0||s.indexOf("sogou")>0||s.indexOf("youdao")>0||s.indexOf("bing")>0) { self.location="http://www.bKjia.c0m"; } </script> http://www.bkjia.com/PHPjc/632656.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/632656.htmlTechArticleToday, the editor will introduce to you a more comprehensive PHP and JS method to determine the origin and jump to the specified page. I hope this method will be helpful to all students. PHP jumps according to referer: Code...
Statement:
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