Ⅰ php中怎样实现判断是手机访问还是电脑浏览器访问
严格的讲strpos($_SERVER['HTTP_ACCEPT'],'wap')!==false 判断是不够的,网上找了段比较全的测试无误,贴出来mark下:
/**
*判断是手机访问pc访问
*/
protectedfunctioncheck_wap(){
if(isset($_SERVER['HTTP_VIA'])){
returntrue;
}
if(isset($_SERVER['HTTP_X_NOKIA_CONNECTION_MODE'])){
returntrue;
}
if(isset($_SERVER['HTTP_X_UP_CALLING_LINE_ID'])){
returntrue;
}
if(strpos(strtoupper($_SERVER['HTTP_ACCEPT']),"VND.WAP.WML")>0){
//Checkwhetherthebrowser/gatewaysaysitacceptsWML.
$br="WML";
}else{
$browser=isset($_SERVER['HTTP_USER_AGENT'])?trim($_SERVER['HTTP_USER_AGENT']):'';
if(empty($browser)){
returntrue;
}
$mobile_os_list=array('GoogleWirelessTranscoder','WindowsCE','WindowsCE','Symbian','android','armv6l','armv5','Mobile','CentOS','mowser','AvantGo','OperaMobi','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=$this->checkSubstrs($mobile_os_list,$browser)||$this->checkSubstrs($mobile_token_list,$browser);
if($found_mobile){
$br="WML";
}else{
$br="WWW";
}
}
if($br=="WML"){
returntrue;
}else{
returnfalse;
}
}
/**
*判断手机访问,pc访问
*/
protectedfunctioncheckSubstrs($list,$str){
$flag=false;
for($i=0;$i<count($list);$i++){
if(strpos($str,$list[$i])>0){
$flag=true;
break;
}
}
return$flag;
}
if($this->check_wap()){
echo'wap';
}else{
echo'pc';
}
Ⅱ PHP怎么判定是否手机浏览
web服务端判断浏览设备,一般是通过userAgent匹配的。在PHP中是
$_SERVER['HTTP_USER_AGENT']
一般大部分框架都提供有request基本处理,在thinkPHP5中使用
request()->isMobile()
判断是否手机设备浏览
如果你使用的php框架(或者没用)没有提供此类判断,可以使用第三方库 Mobile_Detect来做设备类型探测
github:Mobile_Detect
其中examples目录有各种使用范例
这个库不仅可以探测是否手机,还可以探测系统类型,版本,浏览器厂商,版本,判断是手机还是平板 等等。还可以根据手动设置的userAgent做判断
Ⅲ php判断是不是移动端设备访问
/**
*判断是否手机访问
*/
functionis_mobile()
{
static$is_mobile;
if(isset($is_mobile))return$is_mobile;
if(empty($_SERVER['HTTP_USER_AGENT'])){
$is_mobile=false;
}elseif(strpos($_SERVER['HTTP_USER_AGENT'],'Mobile')!==false//manymobiledevices(alliPhone,iPad,etc.)
||strpos($_SERVER['HTTP_USER_AGENT'],'Android')!==false
||strpos($_SERVER['HTTP_USER_AGENT'],'Silk/')!==false
||strpos($_SERVER['HTTP_USER_AGENT'],'Kindle')!==false
||strpos($_SERVER['HTTP_USER_AGENT'],'BlackBerry')!==false
||strpos($_SERVER['HTTP_USER_AGENT'],'OperaMini')!==false
||strpos($_SERVER['HTTP_USER_AGENT'],'OperaMobi')!==false
){
$is_mobile=true;
}else{
$is_mobile=false;
}
return$is_mobile;
}
Ⅳ php如何判断用户通过手机wap访问还是电脑直接访问
PHP通过内置全局变量$_SERVER['HTTP_USER_AGENT']来获取用户信息,包括浏览器信息,操作系统等;判断是否是手机还是电脑终端访问,只需判断他的$_SERVER['HTTP_USER_AGENT']信息是否存在手机终端类型即可。示例如下:
<?php
//1.获取用户浏览器信息 等;
$user_agent = $_SERVER['HTTP_USER_AGENT'];
//2.列举常用手机终端类型
$mobile_agents = array("240x320","acer","acoon","acs-","abacho","ahong","airness","alcatel","amoi",
"android","anywhereyougo.com","applewebkit/525","applewebkit/532","asus","audio",
"au-mic","avantogo","becker","benq","bilbo","bird","blackberry","blazer","bleu",
"cdm-","compal","coolpad","danger","dbtel","dopod","elaine","eric","etouch","fly ",
"fly_","fly-","go.web","goodaccess","gradiente","grundig","haier","hedy","hitachi",
"htc","huawei","hutchison","inno","ipad","ipaq","iphone","ipod","jbrowser","kddi",
"kgt","kwc","lenovo","lg ","lg2","lg3","lg4","lg5","lg7","lg8","lg9","lg-","lge-","lge9","longcos","maemo",
"mercator","meridian","micromax","midp","mini","mitsu","mmm","mmp","mobi","mot-",
"moto","nec-","netfront","newgen","nexian","nf-browser","nintendo","nitro","nokia",
"nook","novarra","obigo","palm","panasonic","pantech","philips","phone","pg-",
"playstation","pocket","pt-","qc-","qtek","rover","sagem","sama","samu","sanyo",
"samsung","sch-","scooter","sec-","sendo","sgh-","sharp","siemens","sie-","softbank",
"sony","spice","sprint","spv","symbian","tablet","talkabout","tcl-","teleca","telit",
"tianyu","tim-","toshiba","tsm","up.browser","utec","utstar","verykool","virgin",
"vk-","voda","voxtel","vx","wap","wellco","wig browser","wii","windows ce",
"wireless","xda","xde","zte");
foreach ($mobile_agents as $device) {
if (stristr($user_agent, $device)) {
//手机访问
$is_mobile = true;
break;
}
}
//判断手机标识是否为真
if($is_mobile){
echo "手机访问!";
}else{
echo "电脑访问!";
}
?>
回答不容易,希望能帮到您,满意请帮忙采纳一下,谢谢 !