2012-07-30 76 views
1

我必須有兩個站點,一個是我的主站點,另一個是移動站點。這是我用於在移動設備中使用移動站點時重定向站點的腳本。現在我想忽略iPad的移動網站重定向。我已經使用這個腳本,但它不忽略iPad,它仍然在移動網站上重定向Ipad,我不想要這個。 Plz的幫助。停止在iPad上重定向移動網站

<?php 
    function check_user_agent ($type = NULL) { 
      $user_agent = strtolower ($_SERVER['HTTP_USER_AGENT']); 
      if ($type == 'bot') { 
        // matches popular bots 
        if (preg_match ("/googlebot|adsbot|yahooseeker|yahoobot|msnbot|watchmouse|pingdom\.com|feedfetcher-google/", $user_agent)) { 
          return true; 
          // watchmouse|pingdom\.com are "uptime services" 
        } 
      } else if ($type == 'browser') { 
        // matches core browser types 
        if (preg_match ("/mozilla\/|opera\//", $user_agent)) { 
          return true; 
        } 
      } else if ($type == 'mobile') { 
        // matches popular mobile devices that have small screens and/or touch inputs 
        // mobile devices have regional trends; some of these will have varying popularity in Europe, Asia, and America 
        // detailed demographics are unknown, and South America, the Pacific Islands, and Africa trends might not be represented, here 


        if(preg_match ("/iPad/", $user_agent)) { 
          return false; 
        } else if (preg_match ("/phone|iphone|itouch|ipod|symbian|android|htc_|htc-|palmos|blackberry|opera mini|iemobile|windows ce|nokia|fennec|hiptop|kindle|mot |mot-|webos\/|samsung|sonyericsson|^sie-|nintendo/", $user_agent)) { 
          // these are the most common 
          return true; 
        } else if (preg_match ("/mobile|pda;|avantgo|eudoraweb|minimo|netfront|brew|teleca|lg;|lge |wap;| wap /", $user_agent)) { 
          // these are less common, and might not be worth checking 
          return true; 
        } 
      } 
      return false; 
    } 
    $ismobile = check_user_agent('mobile'); 
    if($ismobile) { 
    header('Location:mobiles_site_url'); 
    } 
    ?> 
+1

在某些時候[CSS3媒體查詢(http://webdesignerwall.com/tutorials/css3-media-queries)將有廣泛的支持,而這種代碼將不再有必要 – 2012-07-30 04:54:46

回答

2

您的用戶代理字符串,第一行用strtolower()來檢查「的iPad」中有一個大寫字母。

嘗試:

if(preg_match ("/ipad/", $user_agent)) { // all lower case 
    .... 
} 
+0

感謝它看起來像它會工作....你有ipad爲我測試,因爲我沒有... :) – 2012-07-30 05:22:10

+0

我這樣做。代理用戶字符串是:'mozilla/5.0(ipad;像mac os x的cpu os 5_1_1)applewebkit/534.46(khtml,像gecko)version/5.1 mobile/9b206 safari/7534.48.3'之後調用strtolower() 。所以,小寫'ipad'在字符串中,所以它應該可以正常工作。 – Xesued 2012-07-30 05:28:10

+0

你可以理解這一點。但是您可以請打開http://mypartyaid.com/ url,它不應該在http://mypartyaid.com/m上重定向。請讓我知道這個...謝謝:) – 2012-07-30 05:32:17

相關問題