php判断手机访问还是电脑访问示例分享
程序员文章站
2023-11-16 12:29:40
复制代码 代码如下:
<?php
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 '手机登录m.jb51.com';
else
echo '电脑登录www.jb51.com';
?>
复制代码 代码如下:
<?php
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 '手机登录m.jb51.com';
else
echo '电脑登录www.jb51.com';
?>
上一篇: 显示程序执行时间php函数代码
下一篇: php 强制下载文件实现代码