您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息
免费发信息
三六零分类信息网 > 柳州分类信息网,免费分类信息发布

智能判断移动端和电脑浏览器代码

2024/3/22 2:39:47发布17次查看
基于移动端的微信和wap网站开发,日益火起来,下面贴一段智能判断分流的代码,希望对菜鸟有所帮助!
function ismobile(){
$useragent = isset($_server['http_user_agent']) ? $_server['http_user_agent'] : '';
$useragent_commentsblock = preg_match('|\(.*?\)|',$useragent,$matches) --> 0 ? $matches[0] : '';
function checksubstrs($substrs, $text){
foreach ( $substrs as $substr )
if (false !== strpos($text,$substr)) {
return true;
}
return 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'
);
$found_mobile = checksubstrs($mobile_os_list,$useragent_commentsblock) || checksubstrs($mobile_token_list,$useragent);
if ($found_mobile) {
return true;
} else {
return false;
}
}
if (ismobile()) {
echo '手机登录';
header(location:http://xxx/wap); //跳转到移动端网站模块
} else {
echo '电脑登录';
header(location:http://xxx/);//
}
以上是php的代码,如果不管用还可以试试以下js部分的代码
ad:真正免费,域名+虚机+企业邮箱=0元
柳州分类信息网,免费分类信息发布

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录