php检测手机浏览器代码
2012-02-22 14:49
399 查看
<?php
function is_mobile(){
// 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";
return isset($_SERVER['HTTP_X_WAP_PROFILE']) or isset($_SERVER['HTTP_PROFILE']) or preg_match($regex_match, strtolower($_SERVER['HTTP_USER_AGENT']));
}
if ($_GET['mobile']) {
$is_mobile = true;
}
if ($_GET['full']) {
$is_mobile = false;
}
if($is_mobile) {
//it's a mobile browser, do something
header("Location: http://www.php100.com/mobile"); } else {
//it's not a mobile browser, do something else
header("Location: http://www.php100.com/desktop"); // or instead of a redirect, simply build html below
}
?>
function is_mobile(){
// 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";
return isset($_SERVER['HTTP_X_WAP_PROFILE']) or isset($_SERVER['HTTP_PROFILE']) or preg_match($regex_match, strtolower($_SERVER['HTTP_USER_AGENT']));
}
if ($_GET['mobile']) {
$is_mobile = true;
}
if ($_GET['full']) {
$is_mobile = false;
}
if($is_mobile) {
//it's a mobile browser, do something
header("Location: http://www.php100.com/mobile"); } else {
//it's not a mobile browser, do something else
header("Location: http://www.php100.com/desktop"); // or instead of a redirect, simply build html below
}
?>
相关文章推荐
- PHP 检测手机浏览器的代码
- PHP 检测手机浏览器的代码
- js判断手机网站,手机浏览器检测,并跳转到手机网站代码
- 检测是浏览器还是手机,需求为是否支持FLASH,此文为检测是否支持FLASH的代码(含demo下载)
- 检测是浏览器还是手机,需求为是否支持FLASH,此文为检测是否支持FLASH的代码(含demo下载)
- js判断手机网站,手机浏览器检测,并跳转到手机网站代码
- 根据判断PC浏览器类型和手机屏幕像素自动调用不同CSS的代码
- 移动设备、手机浏览器Javascript滑动事件代码
- JavaScript编写检测用户所使用的浏览器的代码示例
- js检测浏览器代码
- 通达OA公共代码 php常用检测函数
- PHP检测用户是否关闭浏览器的方法
- PHP批量检测并去除文件BOM头代码实例
- php中用于检测一个地理IP地址是否可用的代码
- 介绍两种方法来实现不用开浏览器就能运行php代码的方法
- 检测浏览器的版本的js代码
- PHP中通过HTTP_USER_AGENT判断是否为手机移动终端的函数代码
- PHP函数检测客户端是否为手机
- javascript检测浏览器的缩放状态实现代码