【发布时间】:2017-04-09 10:08:24
【问题描述】:
我正在为移动应用程序设计一个 wordpress 网站。 对于访问者,我想显示基于操作系统的文本、图像,如下页 -
https://www.sapphireone.com/accounting-software/accounts/
在此页面中,在“帐户结构部分”中,有一个图像会根据操作系统(即 mac 和 windows)而变化。
我想为 android 和 iPhone 做类似的事情。我正在使用以下代码,但它不起作用。
//function.php 的代码
function find_andoird() {
$ua = $_SERVER[‘HTTPS_USER_AGENT’];
/* ==== Detect the OS ==== */
// Android
$android = strpos($ua, 'Android') ? true : false;
// iPhone
$iphone = strpos($ua, 'iPhone') ? true : false;
return $android;
}
//模板文件代码
if(find_andoird() == true) {
<p><strong>Android View</strong></p>
<p>
<img src=“accounting-android.png” style="float:left;width:400px;height:600px;">
The android view is displayed here.
</p>
}
else {
<p><strong>iPhone View</strong></p>
<p>
<img src=“accounting-iphone.png” style="float:left;width:400px;height:600px;">
The iphone view is displayed here.
</p>
}
}
我能得到一些帮助吗?谢谢
【问题讨论】:
-
更改函数以返回 $ua 值,并将其输出以查看函数正在处理的字符串。
-
首先是
HTTP_USER_AGENT,它周围的引号是错误的,应该是简单的引号 -
搜索
HTTPS_USER_AGENT的第一个链接是How to echo a different title to the page if it's opened on an android mobile phone -
嗨,bansi,我已更改为 $ua = $_SERVER['HTTP_USER_AGENT'];还是不行
-
嗨炫耀者,你能帮帮我吗,怎么做..因为它是在wordpress中,所以我有点困惑。