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元