首页 > 代码库 > php判断是手机还是pc访问

php判断是手机还是pc访问

$is_mobile = false;
$mobile_os_list = array(‘Google Wireless Transcoder‘, ‘Windows CE‘, ‘WindowsCE‘, ‘Symbian‘, ‘Android‘, ‘armv6l‘, ‘armv5‘, ‘Mobile‘, ‘CentOS‘, ‘mowser‘, ‘AvantGo‘, ‘Opera Mobi‘, ‘J2ME/MIDP‘, ‘Smartphone‘, ‘Go.Web‘, ‘Palm‘, ‘iPAQ‘);
$mobile_token_list = array(‘Profile/MIDP‘, ‘Configuration/CLDC-‘, ‘160×160‘, ‘176×220‘, ‘240×240‘, ‘240×320‘, ‘320×240‘, ‘UP.Browser‘, ‘UP.Link‘, ‘SymbianOS‘, ‘PalmOS‘, ‘PocketPC‘, ‘SonyEricsson‘, ‘Nokia‘, ‘BlackBerry‘, ‘Vodafone‘, ‘BenQ‘, ‘Novarra-Vision‘, ‘Iris‘, ‘NetFront‘, ‘HTC_‘, ‘Xda_‘, ‘SAMSUNG-SGH‘, ‘Wapaka‘, ‘DoCoMo‘, ‘iPhone‘, ‘iPod‘);
$is_mobile = false;
foreach ($mobile_os_list as $key => $value) {
    if (strpos($_SERVER[‘HTTP_USER_AGENT‘], $value)) {
        $is_mobile = true;
    }
}
foreach ($mobile_token_list as $key => $value) {
    if (strpos($_SERVER[‘HTTP_USER_AGENT‘], $value)) {
        $is_mobile = true;
    }
}

true 是手机,false是pc。 可以封装成一个方法。 

 

php判断是手机还是pc访问