停止在iPad上重定向移动网站

时间:2012-07-30 04:52:31

标签: php user-agent

我必须有两个站点,一个是我的主站点,另一个站点是移动站点。这是我在移动设备中使用时用于在移动设备上重定向站点的脚本。现在我想忽略iPad的移动网站重定向。我已经使用过这个脚本,但是它没有忽略iPad,它仍然在Ipad上的移动网站上重定向,我不想要这个。 Plz的帮助。

 <?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 个答案:

答案 0 :(得分:2)

您在用户代理字符串上使用了strtolower(),并且检查“iPad”的第一行是否包含大写字母。

尝试:

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