问答文章1 问答文章501 问答文章1001 问答文章1501 问答文章2001 问答文章2501 问答文章3001 问答文章3501 问答文章4001 问答文章4501 问答文章5001 问答文章5501 问答文章6001 问答文章6501 问答文章7001 问答文章7501 问答文章8001 问答文章8501 问答文章9001 问答文章9501

php如何判断用户通过手机wap访问还是电脑直接访问

发布网友 发布时间:2022-04-06 02:15

我来回答

2个回答

懂视网 时间:2022-04-06 06:36

【相关学习推荐:php图文教程】

php判断是手机访问还是电脑访问的方法:

1、如果有HTTP_X_WAP_PROFILE则一定是移动设备

//判断电脑还是手机访问
 function is_mobile(){ 
 
 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;
 }

2、脑残法,判断手机发送的客户端标志,兼容性有待提高

 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;
  } 
 }

3、协议法,因为有可能不准确,放到最后判断

 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编程(视频)

热心网友 时间:2022-04-06 03:44

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 "电脑访问!";
}

?>

回答不容易,希望能帮到您,满意请帮忙采纳一下,谢谢 !
声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com
阳光燕山学校是贵族学校吗 小米14ultra跌至新低 小米14ultra值得购买吗 马卡龙多少钱一个 马卡龙为什么那么贵 正宗马卡龙多少钱一个-马卡龙为什么这么贵 今年河北的迁西板栗多少钱一斤、生的 板栗什么时候上市能卖到几月呢? 6月份能买到新鲜板栗吗? 睡眠银行的生物信息专家林晨瀚讲座谁有听过,对他们的生物信息助眠方法讲 ... 材料力学实验简介 php如何判断是手机访问还是电脑访问 wamp如何升级php apache mysql php.ini怎么设置才能加载 每次重开机时wampserver在桌面右下角处的php.ini文件都成了空文件,是为什么呀。 WAMP中 apache和php目录下的php.ini有什么区别 如何修改wamp的默认访问目录 wamp怎么还原php.ini 有两个PHP.INI文件,选择哪一个修改include_path。安装smarty,我用的是wamp环境。求大神指点。 wampserver怎么修改php版本 怎么修改wampserver2.3 php的错误显示格式 apache如何配置php 5.2.17, php 5.2.17中php.ini又如何配置? wamp 配置 php短标签怎么修改 关于php.ini设置问题怎么可以正常使用&lt;? ?&gt; 我用wamp装了PHP,请问apache下的php.ini 和php文件下 php.ini 有什么区别? 怎么修改wamp php运行目录 修改wamp中的php.ini文件为什么总是没有效果 wampserver 修改php.ini配置问题 PHP,如何从一个数组1到32。随机提取6位数字?不能重复的。 关于PHP随机排序不重复输出的疑问 php随机读取一条数据,但不重复 PHP判断是手机端访问还是PC端访问网站 php检测用户是 手机端还是电脑端 PHP CI 框架 怎么在访问的是否区分手机 和 电脑访问 php 判断是电脑还是手机浏览器打开 php怎么判断客户是用手机还是用电脑访问的网站? php判断用户是电脑还是手机Pad访问 php判断终端是手机还是电脑访问网站 php 获取访问客户端是pc端还是手机端 php如何判断客户端是pc还是手机 php 区分手机 和 pc 访问 ThinkPHP中判断是手机端还是电脑端访问的方法 PHP怎么判断终端是不是电脑访问 php 怎么把当前的日期转换成时间戳 ThinkPHP 如何把获取到的日期格式的时间转化为时间戳 PHP 将输出时间转变为时间戳的问题 登录图片看不清换另一张,如何用js实现 asp.net里的验证码怎么实现 “看不清换一张”是怎么实现的 电脑系统登录时验证码只显示看不清换一张图怎么办? 验证码看不清怎么用程序来实现 为什么我点一下验证码的“看不清换一张”时,页面的所有的内容都没有了呢?怎样才能留住它呢?