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