PHP and JS determine the route to jump to the specified page

Source: Internet
Author: User

Today, I will introduce you to a more comprehensive PHP and JS Judgment Method to jump to the specified page. I hope this method will be helpful to you.

PHP redirection Based on referer:

The Code is as follows: Copy code

<? Php
$ Ref = $ _ SERVER ['HTTP _ referer'];
If (stripos ($ ref, "baidu") | stripos ($ ref, "google ")
{
Header ("Location: http://www.bKjia. c0m ");
Exit;
}
?>

Jump Based on 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.bKjia. c0m ");
}
?>


The header () function is defined as follows:

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

The optional parameter replace indicates whether to replace the previous header or add a header of the same type. The default parameter is replace.

The second optional parameter http_response_code sets the HTTP code as the specified value. The Location header in the header function is a special header call, which is often used to redirect pages. Note: 1. There cannot be spaces between location and:. Otherwise, no jump will be made.

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.bKjia. c0m ";
}
</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.