php判斷手機
Ⅰ php可不可以檢測出手機的品牌,如三星.小米,蘋果,就像qq空間里可以顯示出來一樣
手機都有一個特有的UA標識
Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.23 Mobile Safari/537.36
上面有關鍵詞Android 、Nexus 5。根據這些關鍵詞去判斷手機類型,再對應顯示出來具體的型號就可以了。
PHP中UA可以通過$_SERVER['HTTP_USER_AGENT']讀到。
判斷:
$isIPhone = stripos($_SERVER['HTTP_USER_AGENT'], 'iphone') === false;
UA收集和分析是一項比較繁重的工程。
Ⅱ php判斷用戶是否使用手機設備
php判斷用戶是否使用手機第一步:如果你和我一樣使用的是wordpress,那就復制到主題的 function.php 文件//判斷是否屬手機 function is_mobile() { $user_agent = $_SERVER['HTTP_USER_AGENT']; $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","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"); $is_mobile = false; foreach ($mobile_agents as $device) { if (stristr($user_agent, $device)) { $is_mobile = true; break; } } return $is_mobile; } 第二步:if 語句if( is_mobile() ){ echo "您使用的是手機"; }
Ⅲ ThinkPHP中判斷是手機端還是電腦端訪問的方法
一般是通過訪問的時候請求來源的header頭文件信息來進行判斷的,譬如Android的手機訪問的話一般都會在hedear頭信息裡面帶上Android這樣的信息,同理Iphone、windows phone都會帶。
Ⅳ php判斷是否為手機
$ua = strtolower($_SERVER['HTTP_USER_AGENT']);
$uachar = "/(nokia|sony|ericsson|mot|samsung|sgh|lg|philips|panasonic|alcatel|lenovo|cldc|midp|mobile)/i";
if(($ua == '' || preg_match($uachar, $ua))&& !strpos(strtolower($_SERVER['REQUEST_URI']),'wap'))
{
echo '手機訪問';
}
Ⅳ php 判斷是否是手機瀏覽器訪問
//php載入函數要比載入類要快一些,建議使用函數判斷
/**
*判斷是否是通過手機訪問
*
*/
function isMobile() {
// 如果有HTTP_X_WAP_PROFILE則一定是移動設備
if (isset ($_SERVER['HTTP_X_WAP_PROFILE'])) {
return true;
}
//如果via信息含有wap則一定是移動設備,部分服務商會屏蔽該信息
if (isset ($_SERVER['HTTP_VIA'])) {
//找不到為flase,否則為true
return stristr($_SERVER['HTTP_VIA'], "wap") ? true : false;
}
//判斷手機發送的客戶端標志,兼容性有待提高
if (isset ($_SERVER['HTTP_USER_AGENT'])) {
$clientkeywords = array (
'nokia',
'sony',
'ericsson',
'mot',
'samsung',
'htc',
'sgh',
'lg',
'sharp',
'sie-',
'philips',
'panasonic',
'alcatel',
'lenovo',
'iphone',
'ipod',
'blackberry',
'meizu',
'android',
'netfront',
'symbian',
'ucweb',
'windowsce',
'palm',
'operamini',
'operamobi',
'openwave',
'nexusone',
'cldc',
'midp',
'wap',
'mobile'
);
// 從HTTP_USER_AGENT中查找手機瀏覽器的關鍵字
if (preg_match("/(" . implode('|', $clientkeywords) . ")/i", strtolower($_SERVER['HTTP_USER_AGENT']))) {
return true;
}
}
//協議法,因為有可能不準確,放到最後判斷
if (isset ($_SERVER['HTTP_ACCEPT'])) {
// 如果只支持wml並且不支持html那一定是移動設備
// 如果支持wml和html但是wml在html之前則是移動設備
if ((strpos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') !== false)
&& (strpos($_SERVER['HTTP_ACCEPT'], 'text/html') === false ||
(strpos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') <
strpos($_SERVER['HTTP_ACCEPT'], 'text/html')))) {
return true;
}
}
return false;
}
Ⅵ php如何判斷客戶端是pc還是手機
//判斷是否是手機
functionis_mobile()
{
$agent=strtolower($_SERVER['HTTP_USER_AGENT']);
$is_pc=(strpos($agent,'windowsnt'))?true:false;
$is_mac=(strpos($agent,'macos'))?true:false;
$is_iphone=(strpos($agent,'iphone'))?true:false;
$is_android=(strpos($agent,'android'))?true:false;
$is_ipad=(strpos($agent,'ipad'))?true:false;
if($is_pc){
returnfalse;
}
if($is_mac){
returntrue;
}
if($is_iphone){
returntrue;
}
if($is_android){
returntrue;
}
if($is_ipad){
returntrue;
}
}
Ⅶ PHP判斷手機是IOS還是Android
<?php
if(strpos($_SERVER['HTTP_USER_AGENT'], 'iPhone')||strpos($_SERVER['HTTP_USER_AGENT'], 'iPad')){
echo 'systerm is IOS';
}else if(strpos($_SERVER['HTTP_USER_AGENT'], 'Android')){
echo 'systerm is Android';
}else{
echo 'systerm is other';
}
Ⅷ php怎麼獲取手機來自哪個國家
通過讀取手機型號。
每一部手機都有自己的型號,根據型號就可以判斷手機來自哪個國家。
php語言主要用於Web開發,應用環境相對簡單,底層操作較少涉及,所以語法簡單,概念比較少,很容易學習和使用。
php提供了許多有用的內置函數,為Web開發提供了很多便利,使代碼編寫得更好。