web时代发展到今天已经衍生出很多领域,最重要的就是移动web,目前手机app的大行其道就是对此最好的诠释,当然除了基于JVM的app网站,还有很多“单纯”的手机网站,在此我们权且不去探讨,在此我们谈一下程序中经常使用的探测手机浏览的功能,这样做的好处是可以在使用手机访问例如www.gaoxueping.com的PC网站时候可以做一下跳转,跳转到http://m.gaoxueping.com,在这里分享一段php检测手机浏览访问网站的代码,程序很简单,不做过多解释:[php]
<?php
class CheckMobileBrowse{
public function check(){
// returns true if one of the specified mobile browsers is detected
$regex_match="/(nokia|iphone|android|motorola|^mot\-|softbank|foma|docomo|kddi|up\.browser|up\.link|";
$regex_match.="htc|dopod|blazer|netfront|helio|hosin|huawei|novarra|CoolPad|webos|techfaith|palmsource|";
$regex_match.="blackberry|alcatel|amoi|ktouch|nexian|samsung|^sam\-|s[cg]h|^lge|ericsson|philips|sagem|wellcom|bunjalloo|maui|";
$regex_match.="symbian|smartphone|midp|wap|phone|windows ce|iemobile|^spice|^bird|^zte\-|longcos|pantech|gionee|^sie\-|portalmmm|";
$regex_match.="jig\s browser|hiptop|^ucweb|^benq|haier|^lct|opera\s*mobi|opera\*mini|320x320|240x320|176x220";
$regex_match.=")/i";
if (preg_match($regex_match, strtolower($_SERVER['HTTP_USER_AGENT']))) {
// $mUrl = 'http://m.com'.$_SERVER['REQUEST_URI'];
header("Location:".$mUrl);
}
// return isset($_SERVER['HTTP_X_WAP_PROFILE']) or isset($_SERVER['HTTP_PROFILE']) or preg_match($regex_match, strtolower($_SERVER['HTTP_USER_AGENT']));
}
}
$mobileBrowse = new CheckMobileBrowse();
$mobileBrowse->check();
?>[/php]
php检测手机浏览器
- Blackford
- 0