Check if PHP-page is accessed from an iOS device(检查是否从 iOS 设备访问 PHP 页面)
问题描述
我有一个简单的 PHP 网页,希望返回不同的内容,具体取决于是从 iPhone/iPad 还是从网络浏览器访问.我该怎么做?
I have a simple PHP webpage, and would like to return different content depending if it's accessed from an iPhone/iPad or from a web brower. How can I do that?
推荐答案
使用 $_SERVER['HTTP_USER_AGENT']
中的用户代理,对于简单的检测,您可以使用 this 脚本:
Use the user agent from $_SERVER['HTTP_USER_AGENT']
,
and for simple detection you can use this script:
<?php
//Detect special conditions devices
$iPod = stripos($_SERVER['HTTP_USER_AGENT'],"iPod");
$iPhone = stripos($_SERVER['HTTP_USER_AGENT'],"iPhone");
$iPad = stripos($_SERVER['HTTP_USER_AGENT'],"iPad");
$Android = stripos($_SERVER['HTTP_USER_AGENT'],"Android");
$webOS = stripos($_SERVER['HTTP_USER_AGENT'],"webOS");
//do something with this information
if( $iPod || $iPhone ){
//browser reported as an iPhone/iPod touch -- do something here
}else if($iPad){
//browser reported as an iPad -- do something here
}else if($Android){
//browser reported as an Android device -- do something here
}else if($webOS){
//browser reported as a webOS device -- do something here
}
?>
如果您想了解用户设备的更多详细信息,我建议使用以下解决方案之一:http://51degrees.mobi 或http://deviceatlas.com
If you want to know more details of the user device I recommended to use one of the following solutions: http://51degrees.mobi or http://deviceatlas.com
这篇关于检查是否从 iOS 设备访问 PHP 页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:检查是否从 iOS 设备访问 PHP 页面


基础教程推荐
- 在 Woocommerce 中根据运输方式和付款方式添加费用 2021-01-01
- WooCommerce 中选定产品类别的自定义产品价格后缀 2021-01-01
- Libpuzzle 索引数百万张图片? 2022-01-01
- 超薄框架REST服务两次获得输出 2022-01-01
- 在多维数组中查找最大值 2021-01-01
- XAMPP 服务器不加载 CSS 文件 2022-01-01
- mysqli_insert_id 是否有可能在高流量应用程序中返回 2021-01-01
- 通过 PHP SoapClient 请求发送原始 XML 2021-01-01
- 如何在 PHP 中的请求之间持久化对象 2022-01-01
- 在 PHP 中强制下载文件 - 在 Joomla 框架内 2022-01-01