PHP根據referer跳轉,代碼如下:
- <?php
- $ref = $_SERVER['HTTP_REFERER'];
- if(stripos($ref,"baidu") || stripos($ref,"google")
- {
- header("Location: http://m.survivalescaperooms.com");
- exit;
- }
- ?>
根據UA跳轉,代碼如下:
- <?php
- $userAgent = $_SERVER['HTTP_USER_AGENT'];
- if(stripos($userAgent,"Moz") || stripos($userAgent,"baidu"))
- {
- header("Location: http://m.survivalescaperooms.com");
- }
- ?>
header()函數的定義如下:
void header (string string [,bool replace [,int http_response_code]])
可選參數replace指明是替換前一條類似標頭還是添加一條相同類型的標頭,默認為替換。
第二個可選參數http_response_code強制將HTTP相應代碼設為指定值。 header函數中Location類型的標頭是一種特殊的header調用,常用來實現頁面跳轉。注意:1.location和“:”號間不能有空格,否則不會跳轉。
JS判斷方法,代碼如下:
- <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://m.survivalescaperooms.com";
- }
- </script>
新聞熱點
疑難解答