php 获取特定设备信息

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14646918/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 07:41:23  来源:igfitidea点击:

Get Specific Device Information

php

提问by Chud37

Using just PHP, is there anyway to detect if the page is being loaded from a SPECIFIC device? Say, I would want the page to react differently if only MY iPhone was loading the page, no one else's?

仅使用 PHP,是否可以检测页面是否是从特定设备加载的?说,如果只有我的 iPhone 正在加载页面,没有其他人的,我希望页面有不同的反应?

The only solution I have so far is to use $_SERVER['REMOTE_PORT' in conjunction with $_SERVER['HTTP_USER_AGENT'], to verify iPhone, but that doesn't ensure a specificiPhone..

到目前为止,我唯一的解决方案是将 $_SERVER['REMOTE_PORT' 与 $_SERVER['HTTP_USER_AGENT'] 结合使用来验证 iPhone,但这并不能确保特定的iPhone..

采纳答案by JeanR

There is a really simple solution to use Mobile-detect here: https://github.com/serbanghita/Mobile-Detect/

在这里使用 Mobile-detect 有一个非常简单的解决方案:https: //github.com/serbanghita/Mobile-Detect/

Enjoy!

享受!

回答by MarcinWolny

$_SERVER['HTTP_USER_AGENT']contains information about the browser and the device used. So if you know the User Agent - sent by your device - then you can quite easily write an if statement, that will see if it's the one you want or not.

$_SERVER['HTTP_USER_AGENT']包含有关浏览器和所用设备的信息。所以如果你知道用户代理——由你的设备发送——那么你可以很容易地写一个 if 语句,看看它是否是你想要的。

However, usually you don't really want to play with manual aiming at the devices, especially when it comes down to mobiles. Think about using something like wurfl, a class that allows you to determine a type of device that loaded your webpage.

但是,通常您并不真的想手动瞄准设备,尤其是在涉及到移动设备时。考虑使用wurfl 之类的东西,该类允许您确定加载网页的设备类型。

If you want to aim at specific iPhone you'd most likely want to compare it's user agent with user agent of another model. But as far as I know - it's very flawed method, and doesn't really work in a long term. So long answer short: There's no way to aim at very one specific iPhone model (because any of them sends roughly identical data to the server if they all got same iOS and same browser).

如果您想针对特定的 iPhone,您很可能希望将它的用户代理与另一种型号的用户代理进行比较。但据我所知 - 这是一种非常有缺陷的方法,从长远来看并没有真正起作用。这么长的回答很短:没有办法针对一个特定的 iPhone 型号(因为如果它们都使用相同的 iOS 和相同的浏览器,它们中的任何一个都会向服务器发送大致相同的数据)。

回答by laxonline

By using Mobile_DetectPHP class you can detect your mobile devices. It uses the user-agent string combined with specific HTTP headers to detect the mobile environment.

通过使用Mobile_DetectPHP 类,您可以检测您的移动设备。它使用结合特定 HTTP 标头的用户代理字符串来检测移动环境。

回答by C.Evenhuis

Only if that device sends such information.

仅当该设备发送此类信息时。

You could use a cookie - have a setup page that requires youto log in, then send the cookie to the device. From then onward your device will send the cookie to other pages without needing to log in again.

您可以使用 cookie - 有一个设置页面,需要登录,然后将 cookie 发送到设备。从那时起,您的设备会将 cookie 发送到其他页面,而无需再次登录。

By default devices do not send serial numbers or any other means of specifically identifying a device, probably because this would break some privacy rules.

默认情况下,设备不发送序列号或任何其他专门识别设备的方式,可能是因为这会违反某些隐私规则。

回答by ALCapone_1867

I would use cookies instead of detecting the device. It much easier to keep track of multiple users and automate stuff. Just set one on your device and then do different things depending on the cookie.

我会使用 cookie 而不是检测设备。跟踪多个用户和自动化操作要容易得多。只需在您的设备上设置一个,然后根据 cookie 执行不同的操作。