Ejemplo n.º 1
0
function get_mobile_data($pv_browser_user_agent)
{
    $mobile_browser = '';
    $mobile_browser_number = '';
    $mobile_device = '';
    $mobile_device_number = '';
    $mobile_os = '';
    // will usually be null, sorry
    $mobile_os_number = '';
    $mobile_server = '';
    $mobile_server_number = '';
    // browsers, show it as a handheld, but is not the os
    $a_mobile_browser = array('avantgo', 'blazer', 'elaine', 'eudoraweb', 'iemobile', 'minimo', 'mobile safari', 'mobileexplorer', 'opera mobi', 'opera mini', 'netfront', 'opwv', 'polaris', 'semc-browser', 'up.browser', 'webpro', 'wms pie', 'xiino');
    /*
    This goes from easiest to detect to hardest, so don't use this for output unless you
    clean it up more is my advice.
    Special Notes: do not include milestone in general mobile type test above, it's too generic
    */
    $a_mobile_device = array('benq', 'blackberry', 'danger hiptop', 'ddipocket', ' droid', 'htc_dream', 'htc espresso', 'htc hero', 'htc halo', 'htc huangshan', 'htc legend', 'htc liberty', 'htc paradise', 'htc supersonic', 'htc tattoo', 'ipad', 'ipod', 'iphone', 'kindle', 'lge-cx', 'lge-lx', 'lge-mx', 'lge vx', 'lg;lx', 'nintendo wii', 'nokia', 'palm', 'pdxgw', 'playstation', 'sagem', 'samsung', 'sec-sgh', 'sharp', 'sonyericsson', 'sprint', 'zunehd', 'zune', 'j-phone', 'milestone', 'n410', 'mot 24', 'mot-', 'htc-', 'htc_', 'htc ', 'lge ', 'lge-', 'sec-', 'sie-m', 'sie-s', 'spv ', 'smartphone', 'armv', 'midp', 'mobilephone');
    /*
    note: linux alone can't be searched for, and almost all linux devices are armv types
    ipad 'cpu os' is how the real os number is handled
    */
    $a_mobile_os = array('android', 'epoc', 'cpu os', 'iphone os', 'palmos', 'palmsource', 'windows phone os', 'windows ce', 'symbianos', 'symbian os', 'symbian', 'webos', 'linux armv');
    // sometimes there is just no other id for the unit that the CTS type service/server
    $a_mobile_server = array('astel', 'docomo', 'novarra-vision', 'portalmmm', 'reqwirelessweb', 'vodafone');
    $k_count = count($a_mobile_browser);
    for ($k = 0; $k < $k_count; $k++) {
        if (strstr($pv_browser_user_agent, $a_mobile_browser[$k])) {
            $mobile_browser = $a_mobile_browser[$k];
            // this may or may not work, highly unreliable because mobile ua strings are random
            $mobile_browser_number = get_item_version($pv_browser_user_agent, $mobile_browser);
            break;
        }
    }
    $k_count = count($a_mobile_device);
    for ($k = 0; $k < $k_count; $k++) {
        if (strstr($pv_browser_user_agent, $a_mobile_device[$k])) {
            $mobile_device = trim($a_mobile_device[$k], '-_');
            // but not space trims yet
            if ($mobile_device == 'blackberry') {
                get_set_count('set', 0);
            }
            $mobile_device_number = get_item_version($pv_browser_user_agent, $mobile_device);
            $mobile_device = trim($mobile_device);
            // some of the id search strings have white space
            break;
        }
    }
    $k_count = count($a_mobile_os);
    for ($k = 0; $k < $k_count; $k++) {
        if (strstr($pv_browser_user_agent, $a_mobile_os[$k])) {
            $mobile_os = $a_mobile_os[$k];
            // this may or may not work, highly unreliable
            $mobile_os_number = str_replace('_', '.', get_item_version($pv_browser_user_agent, $mobile_os));
            break;
        }
    }
    $k_count = count($a_mobile_server);
    for ($k = 0; $k < $k_count; $k++) {
        if (strstr($pv_browser_user_agent, $a_mobile_server[$k])) {
            $mobile_server = $a_mobile_server[$k];
            // this may or may not work, highly unreliable
            $mobile_server_number = get_item_version($pv_browser_user_agent, $mobile_server);
            break;
        }
    }
    // just for cases where we know it's a mobile device already
    if (!$mobile_os && ($mobile_browser || $mobile_device || $mobile_server) && strstr($pv_browser_user_agent, 'linux')) {
        $mobile_os = 'linux';
        $mobile_os_number = get_item_version($pv_browser_user_agent, 'linux');
    }
    $a_mobile_data = array($mobile_device, $mobile_browser, $mobile_browser_number, $mobile_os, $mobile_os_number, $mobile_server, $mobile_server_number, $mobile_device_number);
    return $a_mobile_data;
}
Ejemplo n.º 2
0
/**
thanks to this page: http://www.zytrax.com/tech/web/mobile_ids.html
for data used here
**/
function get_mobile_data($pv_browser_user_agent)
{
    $mobile_browser = '';
    $mobile_browser_number = '';
    $mobile_device = '';
    $mobile_device_number = '';
    $mobile_os = '';
    // will usually be null, sorry
    $mobile_os_number = '';
    $mobile_server = '';
    $mobile_server_number = '';
    $mobile_tablet = '';
    // browsers, show it as a handheld, but is not the os
    // note: crios is actuall chrome on ios, uc need to be before safari
    // Mozilla/5.0 (Windows Phone 10.0; Android 4.2.1; DEVICE INFO) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Mobile Safari/537.36 Edge/12.<OS build number>
    $a_mobile_browser = array('avantgo', 'blazer', 'crios', 'elaine', 'eudoraweb', 'fennec', 'iemobile', 'minimo', 'ucweb', 'ucbrowser', 'mobile safari', 'mobileexplorer', 'opera mobi', 'opera mini', 'netfront', 'opwv', 'polaris', 'puffin', 'samsungbrowser', 'semc-browser', 'silk', 'steel', 'ultralight', 'up.browser', 'webos', 'webpro/', 'wms pie', 'xiino');
    /**
    	This goes from easiest to detect to hardest, so don't use this for output unless you
    	clean it up more is my advice.
    	Special Notes: do not include milestone in general mobile type test above, it's too generic
    	Note: we can safely now test for zune because the initial test shows zune with iemobile in ua
    	**/
    $a_mobile_device = array('benq', 'blackberry', 'danger hiptop', 'ddipocket', ' droid', 'htc_dream', 'htc espresso', 'htc hero', 'htc halo', 'htc huangshan', 'htc legend', 'htc liberty', 'htc paradise', 'htc supersonic', 'htc tattoo', 'ipad', 'ipod', 'iphone', 'kindle', 'kobo', 'lge-cx', 'lge-lx', 'lge-mx', 'lge vx', 'lg;lx', 'nexus', 'nintendo wii', 'nokia', 'nook', 'palm', 'pdxgw', 'playstation', 'sagem', 'samsung', 'sec-sgh', 'sharp', 'sonyericsson', 'sprint', 'j-phone', 'milestone', 'n410', 'mot 24', 'mot-', 'htc-', 'htc_', 'htc ', 'lge ', 'lge-', 'sec-', 'sie-m', 'sie-s', 'spv ', 'smartphone', 'midp', 'mobilephone', 'wp', 'zunehd', 'zune');
    /**
    	note: linux alone can't be searched for, and almost all linux devices are armv types
    	ipad 'cpu os' is how the real os number is handled : could be an arm laptop, don't use 'linux armv'
    	note: the new windows 10 phone os ua has 'android' in it for some reason, so it goes first.
    	Mozilla/5.0 (Windows Phone 10.0; Android 4.2.1; DEVICE INFO) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Mobile Safari/537.36 Edge/12.0
    	**/
    $a_mobile_os = array('windows phone os', 'windows phone', 'android', 'blackberry', 'epoc', 'cpu os', 'iphone os', 'palmos', 'palmsource', 'windows ce', 'symbianos', 'symbian os', 'symbian', 'webos');
    // sometimes there is just no other id for the unit that the CTS type service/server
    $a_mobile_server = array('astel', 'docomo', 'novarra-vision', 'portalmmm', 'reqwirelessweb', 'vodafone');
    /**
    	basic tablet detection. Note, android 3 was a tablet only release, android 4 is
    	mobile/tablet. gt-p is samsung galaxy tablet (eg, gt-p = gt-p1000); verizon galaxy: SCH-I(xxx)
    	sm-t is SM-T211 galaxy tab 3. Highly unreliable user agents though.
    	note: android 4 is a special case, and is only a tablet if the word 'mobile' is NOT in the string.
    	Rather than loop through everything we'll test this manually below and only run the loop if not found.
    	NOTE that silk can only be tested for AFTER it's determined it's an android device, changed below to kindle
    	https://amazonsilk.wordpress.com/useful-bits/silk-user-agent/
    	cros: X11; CrOS armv7l 6680.81.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.118 Safari/537.36
    	' sch-i' is not accurate for tablets
    	**/
    $a_mobile_tablet = array('ipad', 'android 3', 'cros', ' gt-p', 'sm-t', 'kindle', 'kobo', 'nook', 'playbook', 'silk', 'touchpad', 'tablet', 'xoom');
    $k_count = count($a_mobile_browser);
    for ($k = 0; $k < $k_count; $k++) {
        if (strstr($pv_browser_user_agent, $a_mobile_browser[$k])) {
            $mobile_browser = $a_mobile_browser[$k];
            // this may or may not work, highly unreliable because mobile ua strings are random
            $mobile_browser_number = get_item_version($pv_browser_user_agent, $mobile_browser);
            break;
        }
    }
    $k_count = count($a_mobile_device);
    for ($k = 0; $k < $k_count; $k++) {
        if (strstr($pv_browser_user_agent, $a_mobile_device[$k])) {
            $mobile_device = trim($a_mobile_device[$k], '-_');
            // but not space trims yet
            if ($mobile_device == 'blackberry') {
                get_set_count('set', 0);
            }
            $mobile_device_number = get_item_version($pv_browser_user_agent, $mobile_device);
            $mobile_device = trim($mobile_device);
            // some of the id search strings have white space
            break;
        }
    }
    $k_count = count($a_mobile_os);
    for ($k = 0; $k < $k_count; $k++) {
        if (strstr($pv_browser_user_agent, $a_mobile_os[$k])) {
            $mobile_os = $a_mobile_os[$k];
            if ($mobile_os != 'blackberry') {
                // this may or may not work, highly unreliable
                $mobile_os_number = str_replace('_', '.', get_item_version($pv_browser_user_agent, $mobile_os));
            } else {
                $mobile_os_number = str_replace('_', '.', get_item_version($pv_browser_user_agent, 'version'));
                // eg: BlackBerry9000/5.0.0.93 Profile/M....
                if (empty($mobile_os_number)) {
                    get_set_count('set', 5);
                    $mobile_os_number = str_replace('_', '.', get_item_version($pv_browser_user_agent, $mobile_os));
                }
            }
            break;
        }
    }
    $k_count = count($a_mobile_server);
    for ($k = 0; $k < $k_count; $k++) {
        if (strstr($pv_browser_user_agent, $a_mobile_server[$k])) {
            $mobile_server = $a_mobile_server[$k];
            // this may or may not work, highly unreliable
            $mobile_server_number = get_item_version($pv_browser_user_agent, $mobile_server);
            break;
        }
    }
    // special case, google isn't showing tablet in the UA, but if it does not say 'mobile' in the ua,
    // the device is tablet. This will probably change over time since mobile ua's are not settled.
    // using regex (?!mobile) did not work in my tests, not sure why.
    $pattern = '/android[[:space:]]*[4-9]/';
    if (preg_match($pattern, $pv_browser_user_agent) && !stristr($pv_browser_user_agent, 'mobile')) {
        $mobile_tablet = 'android tablet';
    } else {
        $k_count = count($a_mobile_tablet);
        for ($k = 0; $k < $k_count; $k++) {
            if (strstr($pv_browser_user_agent, $a_mobile_tablet[$k])) {
                $mobile_tablet = trim($a_mobile_tablet[$k]);
                if ($mobile_tablet == 'gt-p' || $mobile_tablet == 'sch-i' || $mobile_tablet == 'sm-t') {
                    $mobile_tablet = 'galaxy-' . $mobile_tablet;
                } elseif ($mobile_tablet == 'silk') {
                    $mobile_tablet = 'kindle fire';
                }
                break;
            }
        }
    }
    // just for cases where we know it's a mobile device already
    if (!$mobile_os && ($mobile_browser || $mobile_device || $mobile_server) && strstr($pv_browser_user_agent, 'linux')) {
        $mobile_os = 'linux';
        $mobile_os_number = get_item_version($pv_browser_user_agent, 'linux');
    }
    $a_mobile_data = array($mobile_device, $mobile_browser, $mobile_browser_number, $mobile_os, $mobile_os_number, $mobile_server, $mobile_server_number, $mobile_device_number, $mobile_tablet);
    return $a_mobile_data;
}