如何检测Android手机和Android平板电脑使用不同的用户代理头? [英] How can I detect Android phones and Android tablets differently using the user agent header?

查看:360
本文介绍了如何检测Android手机和Android平板电脑使用不同的用户代理头?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有关我的地盘我需要能够告诉当一个Android平板电脑访问,当Android手机访问的区别。它需要在将页面发送到如此使用JavaScript来检查屏幕资源的用户被检测到不是一种选择。

For my site I need to be able to tell the difference between when an Android tablet visits and when an Android phone visits. It needs to be detected before the page is sent to the user so using JavaScript to check the screen res isn't an option.

在我使用它来检测Android设备的时刻:
stripos函数($ UA,'机器人')

At the moment I use this to detect an android device: stripos($ua, 'android')

有什么独特的塔尔平板电脑拥有它的用户代理?

Is there anything unique thar a tablet has in it's user agent?

推荐答案

您可以使用PHP的$ _ SERVER ['HTTP_USER_AGENT'],然后区分大小写eregi功能,查找下面,假设该浏览器开发商随后Android的用户指南代理规范:

You can use PHP's $_SERVER['HTTP_USER_AGENT'] then case-insensitive eregi functions to look for the following, which assumes the browser developer followed Android's guidelines on user agent specification:

$ua = $_SERVER['HTTP_USER_AGENT'];
if (eregi('Android', $ua) && eregi('Mobile', $ua)) $platform = "Android Phone";
elseif (eregi('Android', $ua) && !eregi('Mobile', $ua)) $platform = "Android Tablet";

这不是万无一失的,但它是一个开始。

It's not foolproof but it's a start.

这篇关于如何检测Android手机和Android平板电脑使用不同的用户代理头?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆