在PHP 开发中如何判断用户是否使用手机?
发布网友
发布时间:2022-04-23 07:02
我来回答
共1个回答
热心网友
时间:2022-04-18 13:17
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如何判断用户通过手机wap访问还是电脑直接访问
PHP通过内置全局变量$_SERVER['HTTP_USER_AGENT']来获取用户信息,包括浏览器信息,操作系统等;判断是否是手机还是电脑终端访问,只需判断他的$_SERVER['HTTP_USER_AGENT']信息是否存在手机终端类型即可。示例如下:<?php //1.获取用户浏览器信息 等;user_agent = $_SERVER['HTTP_USER_AGENT'];/...
请问:php如何判断用户是使用pc电脑浏览网页 还是移动设备来浏览网页呢...
安卓手机和安卓平板 不一定就能区分开 //获取浏览器 function getBrowse(){ global $_SERVER;Agent = $_SERVER['HTTP_USER_AGENT'];browseinfo='';if(ereg('Mozilla', $Agent) && !ereg('MSIE', $Agent)){ browseinfo = 'Netscape Navigator';} if(ereg('Opera', $Agent)) { browseinfo ...
如何判断用户是通过手机浏览还是电脑浏览网站
在以上代码中,如果如果flag返回值为true则说明是电脑客户端,如果是false,则说明使用的是移动客户端,代码比较简单这里就不多介绍了,直接套用就可以了
php聊天系统怎么样判断用户是不是在线
方案一、用户登陆成功后,将用户的信息,如用户ID保存到session当中去,然后我们去判断session当中是否有当前用户ID就可以判断出该用户是否在线了,然后用户退出的时候,将此session清除就可以啦;方案二、用户表设置一个字段,用于保存用户的登陆状态,如果用户登陆成功才设置成1,否则设置成0,然后当要判断...
PHP网站中,如何判断用户是否是在线的状态?
普通http网站是一种无状态连接,每次一个请求,一个应答,没有长连接状态。但是可以通过记录访问时间,来确定用户的状态。用户登录后,每次访问,更新一下最近访问时间在数据库里 在用户页面的公共部分,做一个定时轮询,n秒一次(防止用户打开页面后放着不动,看资料或者做别的)服务器端做一个定时,将...
PHP如何判断用户是否登陆,防止同账号多登陆,
当用户登陆的时候,检测和用户uid相关的token表,如果已经有token了,并且本次的设备唯一识别号和已经登陆的识别号不一样,那么清空原有token,也就是将原来登陆的账号踢下线。记录新的设备识别号的token即可。php大致代码如下:$currentDeviceUUID=getDeviceUUID();$uid = getUserId();$token = ...
php中在进入一个界面不登陆用户的情况下显示需要登录的弹窗,并且返回登 ...
在基础控制器中判断这个用户是否登陆,如果没有登录就弹窗提示,并跳转到登录页面
...网站时,他们的手机号如何能记录下来。网站语言是PHP
php没办法记录他们的电话号码,只有你是开发手机客服端的时候才会有机会,比如你开发android和iphone手机的应用,如果你要调用手机号的接口必须打开权限,而且即使你完成应用的开发,在你使用什么手机杀毒软件也会提示你,这个应用在读取你手机号码有涉及隐私,就是涉及隐私问题。。
PHP程序中如何判断来访者是蜘蛛还是普通用户?
根据在一定时间打开的链接和流量多少来判断。如果用脚本的话,可以这样在全局配置文件里记录访问各个页面的ip地址、访问时间、访问的脚本页面,那么你根据某个ip在短时间内访问到多个页面,就可以认定是蜘蛛,否则为普通用户。
在php 编程中.怎么能判定用户是否停留在某个页面上?
用JS判断吧 window.focus 返回焦点是否处于当前窗口 如果是true,那么就说明用户停留在这个页面