使用php检测特定的iPhone或iPad型号 [英] Detect specific iPhone or iPad model with php

查看:86
本文介绍了使用php检测特定的iPhone或iPad型号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的网站出售iPhone,iPad和iPod的配件,零件和维修,我想根据他们正在浏览的特定iPhone/iPad/iPod型号,为用户可能要寻找的类别提供链接建议.使用PHP.

我知道我可以使用标头来检测它是iPhone,iPad还是iPod,但是由于我有很多类别,因此我希望它更具体一些,并区分iPhone 3G,4和iPhone 5,以及iPad.我是对的,标题没有提供有关特定型号的任何信息吗?

另一种方法是使用CSS3来检查浏览器的分辨率,但对于SEO而言,对于不正确的"模型使用大量的显示:无;"可能是一个灾难-尤其是因为隐藏的内容会主要是链接.

是使用php标头检查它是iPhone,iPad还是iPod,然后再尝试使用CSS媒体查询来区分特定型号的唯一解决方案吗?这似乎不是最佳选择,我怀疑我是否有办法检测第三代iPad和第四代iPad(视网膜)之间的差异,因为据我所知它们具有相同的标头和相同的分辨率://>

关于如何实现此目标的任何建议?

更新:另一种方法可能是使用javascript进行检测,并设置一个可以由php处理的cookie,如下面的链接所述,但它仍然无法提供区分具有相同分辨率和类型的设备的方法(iPad 3/4,iPod Touch 2/3,iPhone 4/4S). http: //www.bdoran.co.uk/2010/07/19/detecting-the-iphone4-and-resolution-with-javascript-or-php/

解决方案

我一直在研究一个需要我检测确切的iOS设备的项目.首先,它位于前端,因此我使用了以下CSS媒体查询来加载资产并根据设备精确调整布局:

// Media queries for iPhone -webkit-text-size-adjust

// iPhone 5 & 5S in portrait & landscape
@media only screen and (min-device-width: 320px) and (max-device-width: 330px) {
    // ...
}

// iPhone 6, 7, & 8 in portrait & landscape
@media only screen and (min-device-width: 375px) and (max-device-width: 667px) {
    // ...
}

// iPhone X in portrait & landscape
@media only screen and (min-device-width: 375px) and (max-device-width: 812px) and (-webkit-device-pixel-ratio: 3) {
    // ...
}

// iPhone 6, 7, & 8 Plus in portrait & landscape
@media only screen and (min-device-width: 414px) and (max-device-width: 736px) {
    // ...
}

这里有XR和XS Max的新功能: iPhone XR/XS/XS Max CSS媒体查询

如果这是一个登录页面,并且您要链接到特定于设备的子页面,那么我认为这不会对SEO造成太大影响.

My site sells accessories, spare parts and repairs for iPhone, iPad and iPod and I'd like to give link suggestions for the categories the user might be looking for according to the specific iPhone/iPad/iPod model they're browsing from, using PHP.

I know I can use the header to detect if it's an iPhone, iPad or iPod but since I have a lot of categories I'd like it to be more specific and differentiate between iPhone 3G, 4 and iPhone 5 and likewise for iPad. Am I right the header doesn't give any info about the specific model?

Another way would be using CSS3 to check the browser resolution, but SEO-wise it could be a disaster to use a lot of "display: none;"'s for the "incorrect" models - especially since the hidden content would be mostly links.

Is the only solution to check if it's an iPhone, iPad or iPod using the php header and then afterwards try to differentiate the specific models using css media queries? It doesn't seem optimal and I doubt I would have a way to detect the difference between an iPad 3rd generation and an iPad 4th generation (Retina) since they have the same header and the same resolution as far as I know :/

Any suggestions on how I might achieve this?

Update: Another way could be to detect using javascript and set a cookie that can be handled by php as described on the link below, but it still doesn't give a way to differentiate devices with the same resolution and type (iPad 3 / 4, iPod Touch 2/3, iPhone 4/4S). http://www.bdoran.co.uk/2010/07/19/detecting-the-iphone4-and-resolution-with-javascript-or-php/

解决方案

I've been working on a project that requires me to detect the exact iOS device. To begin with, it was on the front end so I used these CSS media queries to load assets and adjust the layout precisely based on the device:

// Media queries for iPhone -webkit-text-size-adjust

// iPhone 5 & 5S in portrait & landscape
@media only screen and (min-device-width: 320px) and (max-device-width: 330px) {
    // ...
}

// iPhone 6, 7, & 8 in portrait & landscape
@media only screen and (min-device-width: 375px) and (max-device-width: 667px) {
    // ...
}

// iPhone X in portrait & landscape
@media only screen and (min-device-width: 375px) and (max-device-width: 812px) and (-webkit-device-pixel-ratio: 3) {
    // ...
}

// iPhone 6, 7, & 8 Plus in portrait & landscape
@media only screen and (min-device-width: 414px) and (max-device-width: 736px) {
    // ...
}

There are new ones for the XR and XS Max here: iPhone XR / XS / XS Max CSS media queries

I don't think it would be much of an SEO disaster if this is a landing page and you have device-specific sub-pages you're linking to.

这篇关于使用php检测特定的iPhone或iPad型号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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