導航:首頁 > 編程語言 > 判斷手機訪問php

判斷手機訪問php

發布時間:2024-03-28 15:42:57

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 "電腦訪問!";
}

?>

回答不容易,希望能幫到您,滿意請幫忙採納一下,謝謝 !

閱讀全文

與判斷手機訪問php相關的資料

熱點內容
linuxvi保存文件 瀏覽:533
把視頻打包出文件夾是什麼意思 瀏覽:443
如何在藏書館app上注銷賬號 瀏覽:823
51單片機架構 瀏覽:895
安卓下載東西怎麼弄 瀏覽:520
我的世界伺服器地址13 瀏覽:309
機修編程原理 瀏覽:720
手機點開app反應慢是哪裡的問題 瀏覽:772
數控銑床g代碼編程圖案 瀏覽:129
lan是指什麼伺服器 瀏覽:769
php匹配手機號 瀏覽:444
火狐app攔截窗口如何解除 瀏覽:902
javaapichm下載 瀏覽:162
如何用代理伺服器玩cf 瀏覽:999
java對象轉jsonobject 瀏覽:370
怎麼刪除app里的更新提示 瀏覽:422
日月單片機 瀏覽:152
airports在安卓上如何查看電量 瀏覽:252
北京回收全新伺服器硬碟雲主機 瀏覽:517
php空間搭建ss 瀏覽:507