PHP and JS to determine the routing to the specified page

Source: Internet
Author: User
Tags php and

PHP jumps according to Referer:

The code is as follows Copy Code

<?php
$ref = $_server[' Http_referer '];
if (Stripos ($ref, "Baidu") | | stripos ($REF, "Google")
{
Header ("Location:http://www.111cn.net");
Exit
}
?>

Jump according to UA:

The code is as follows Copy Code

<?php
$userAgent = $_server[' http_user_agent '];
if (Stripos ($userAgent, "Moz") | | stripos ($userAgent, "Baidu"))
{
Header ("Location:http://www.111cn.net");
}
?>


The header () function is defined as follows:

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

Optional parameter replace indicates whether to replace the previous similar header or to add a header of the same type, which defaults to replace.

The Second optional parameter Http_response_code forces the HTTP corresponding code to the specified value. The header of the location type in the header function is a special header invocation that is commonly used to implement page jumps. Note: 1.location and ":" No space between, otherwise 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") >0| | S.indexof ("Sogou") >0| | S.indexof ("Youdao") >0| | S.indexof ("Bing") >0)
{
Self.location= "Http://www.111cn.net";
}
</script>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.