当前位置:首页 » 编程语言 » php判断手机

php判断手机

发布时间: 2023-03-02 18:08:10

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开发提供了很多便利,使代码编写得更好。

热点内容
安卓原生系统开发者模式在哪里 发布:2024-11-07 11:22:47 浏览:408
pythongdal安装 发布:2024-11-07 11:07:29 浏览:288
怎么用电脑开手机服务器 发布:2024-11-07 10:30:50 浏览:501
代挂网源码最新版 发布:2024-11-07 10:28:30 浏览:820
atoilinux 发布:2024-11-07 10:19:06 浏览:462
速腾哪个配置性能好 发布:2024-11-07 09:55:08 浏览:622
压缩空气的价格 发布:2024-11-07 09:51:25 浏览:541
达内培训班java 发布:2024-11-07 09:51:19 浏览:315
c语言快速排序函数 发布:2024-11-07 09:41:16 浏览:210
mobisage文件夹 发布:2024-11-07 09:29:16 浏览:877